Design Pattern) 단순 팩토리 - Simple Factory
목차) - 단순 팩토리이란 - 단순 팩토리 사용법 - 단순 팩토리 사용이유 - 활용 예시 - 느낀점 - 단순 팩토리이란? 클래스 내부에서 객체를 인스턴스화를 하게 되면 그 객체는 생성한 클래스랑 결합관계가 됩니다. 그 결합관계는 나중에 코드 수정이나 확장할 경우 비용이 많이 들게 되겠죠. 이런 문제를 해결하고자 객체 생성만 하는 클래스를 따로 만들어 제공하면 추후에 수정이나 확장할 때 용이하게 만들어줍니다. 이렇게 특정 객체를 생성한 후 반환해주는 클래스를 가르켜 팩토리라고 합니다. 이중에서 객체를 리턴해주는 메소드와 객체의 개수가 일치하는 클래스를 단순 팩토리라고 부릅니다. - 단순 팩토리 사용법 기본적으로 객체를 생성하는 팩토리 클래스가 있으며 다른 객체를 생성해 반환해주는 메소드가 존재합니다. 보통..
2021. 2. 5. 00:37