나를 위한 면접 (Backend Developer Interview Questions)
· 약 27분
BE Interview Questions를 아는 만큼 답해보았다 지극히 주관적이라 정답이 아닐 수 있습니다
Why are global and static objects evil?
- 전역변수는 어디서 변경되었는지 추적이 힘듦
- 그리고 자바의 경우 콜스택이 끝나면 비워지는 지역변수와 달리 메모리의 static 영역에 계속 상주해 있음
Tell me about Inversion of Control and how does it improve the design of code
- 클래스 안에 다른 클래스의 기능이 필요하다면 내부에서 생성자를 이용해 두 클래스 간의 종속이 생겨버리는데
- IoC를 통한다면 DI 패턴으로 구현해
new A(new B())
처럼 종속성을 분리시킬 수 있음 - TypeHint를 통해 의존성을 확인할 수 있으므로 더 직관적이기도 하다
- What is Inversion of Control?
Active-Record is the design pattern that promotes objects to include functions such as Insert, Update, and Delete, and properties that correspond to the columns in some underlying database table. In your opinion and experience, which are the limits and pitfalls of the this pattern?
- 장점
- 하나의 구조로 모든 모델을 제어할 수 있게 해준다.
- 또한 모든 DB 마다 다른 쿼리문 (예를 들어 페이징)을 손쉽게 처리할 수도 있다.
- 무엇보다 엄청 빠르게 DB 조작이 가능해진다.
- 단점
- DB를 잊어버리게 되는 것 아닐까? ActiveRecord로 개발을 시작하는 건 아니다라고 본다.
- 여러 테이블의 조인이 힘들고 (조인 조건을 만족하기 위해) 계산이 들어간 쿼리문이라면 어차피 RAW 쿼리를 날려야한다.
- 프로시져를 사용할 수도 없고, 관계형 모델들은 select를 키값을 통해 여러 번 select 한 뒤 합쳐주는 것 뿐이라 성능상의 이슈도 있다.
- 결국 필요한 곳에서만 (RESTful 구조의) 사용해서 개발하는 게 좋을 것 같다
Data-Mapper is a design pattern that promotes the use of a layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself. On the contrary, in Active-Record objects directly incorporate operations for persisting themselves to a database, and properties corresponding to the underlying database tables. Do you have an opinion on those patterns? When would you use one against the other?
The big benefit of the Data Mapper pattern is, your domain objects don't need to know anything about how they are stored in the database. This means that your objects will be lighter because they don't have to inherit the full ORM, but also there will be a stricter, more formal process for interacting with the database because you can't just call the save() method anywhere in your code
- 데이터 매퍼는 DB 스키마와 독립적인 모델을 갖고 싶을 때 사용한다
- ActiveRecord의 속도보다 성능이 필요한 경우 사용하면 된다.
- What's the difference between Active Record and Data Mapper
Why it is often said that the introduction of null is a "Billion dollar mistake"? Would you discuss the techniques to avoid it, such as the Null Object Pattern introduced by the GOF book, or Option types?
- null 로 변수를 생성하는 건 안하는 거랑 똑같지만, 안 해주면 프로그램이 뻗어버려서 null 타입 체크를 하거나 default값을 추가한다.
- 10억 달러짜리 실수
Many state that, in Object-Oriented Programming, Composition is often a better option than Inheritance. What's you opinion?
- 부모-자식 관계면 상속이지만, Has 관계이면 컴포지션
- 잘못 알려진 디자인 패턴의 두번째 원칙
What is an Anti-corruption Layer?
- 추상화 한 레이어를 하나 더 두고 하위 도메인들을 쉽게 접근할 수 있게 하는 방법, facade 처럼
Singleton is a design pattern that restricts the instantiation of a class to one single object. Writing a Thread-Safe Singleton class is not so obvious. Would you try?
Volatile
How would you deal with Dependency Hell?
- 의존성 컨테이너를 사용한다.
- 패키지 매니저툴을 이용하며 버전을 명시한다.
- maven, composer, npm 등등
Is goto evil?
- 적절하게, 가독성 있게 사용하면 괜찮다.
- 리눅스 커널 이런 느낌으로
Code Design
It is often heard that one of the most important goals in Object-Oriented Design is to have High Cohesion and Loose Coupling. What does it mean? Why is it that important and how is it achieved?
- Coupling
- 모듈 간에 상호 의존하는 정도
- 각 모듈 간의 결합도가 약해야 하며 의존하는 모듈이 적어야한다.
- 결합도가 강하면 시스템 구현 및 유지보수 작업이 어렵다.
- Cohesion
- 정보 은닉 개념을 확장한 것
- 명령어나 호출문 등 모듈의 내부 요소들의 서로 관련되어 있는 정도
- 모듈이 독립적인 기능으로 정의되어 있는 정도
- 독립적인 모듈이 되기 위해서는 각 모듈의 응집도가 강해야한다
Why does array index start with '0' in most of languages?
- 배열이 참조하는 메모리의 위치를 나타내므로 (시작 위치에서의 기준점)
Are comments in code useful? Some say they should be avoided as much as possible, and hopefully made unnecessary
- 변수명, 메소드명으로 명확하게 표현할 수 있으면 좋은데, 그러긴 현실적으로 힘들고
- JSDoc 같은 구문으로 주석을 단다면 참조하는 다른 소스에서도 hover만으로 모든 설명을 볼 수 있어서도 좋고
What is the difference between design and architecture?
- Software architecture is more about the design of the entire system, while software design emphasizes on module / component / class level.
- Architecture: MVC, 3-tier layered design, etc.
- Design: What are the responsibilities, functions, of module x? Of class Y? What can it do, and what not?
- Software Design vs. Software Architecture
C++ supports multiple inheritance, and Java allows a class to implement multiple interfaces. What impact does using these facilities have on orthogonality? Is there a difference in impact between using multiple inheritance and multiple interfaces? Is there a difference between using delegation and using inheritance?
- implements가 좀 더 유연하다 클래스 안에서 직접 구현해야되는거니까
Pros and cons of holding domain logic in Stored Procedures
- 장점
- 한 번 만든걸 계속 호출해서 쓸 수 있음
- 컴파일 언어의 경우 쿼리만 변경하는거니 유지보수가 좋을 수 있음
- 계산이 들어가는 쿼리의 경우 SP는 캐싱되므로 이만한게 없음
- 단점
- DB에 완전 종속됨
- DBA가 있어야함
- git에서 변경점 추적 불가능