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 처럼