OOP 디자인 패턴에서 싱글레톤(Singleton) 패턴은 왜 있는 건가요?
그냥 클래스의 생성자는 private로 선언해버리고, 필요한 멤버나 메쏘드를
static으로 선언해서 객체를 생성하지 않고, 그냥 클래스에 바로 접근을 하면
마치 객체가 하나인것 과 똑같은 효과가 나지 않나요?
The difference between the two is subtle. For one thing, because singleton access is managed by a class method, you can add additional logic to that method. More abstractly, the point of a singleton is to ensure that a class has only one instance (strictly speaking this is not true, according to the GoF book a singleton could return instances from a pool, and because you have to go through the getInstance() method you wouldn't have to worry about it -though in some case you will most definitely know it-. This is stated as being one of the benefits of the singleton in the GoF book). SingletonPattern has to do with how to limit instances, while GlobalVariables are more related to how programmers declare instances.
The difference between the two is subtle
The difference between the two is subtle. For one thing, because singleton access is managed by a class method, you can add additional logic to that method. More abstractly, the point of a singleton is to ensure that a class has only one instance (strictly speaking this is not true, according to the GoF book a singleton could return instances from a pool, and because you have to go through the getInstance() method you wouldn't have to worry about it -though in some case you will most definitely know it-. This is stated as being one of the benefits of the singleton in the GoF book). SingletonPattern has to do with how to limit instances, while GlobalVariables are more related to how programmers declare instances.
라고 하는군요..
Mono state 패턴 이라고 있습니다.말씀하신게 모노스테이트
Mono state 패턴 이라고 있습니다.
말씀하신게 모노스테이트 패턴입니다.
Gof 에는 없고 AgilePPP 책에 보면 나오는데
싱글턴과의 차이는 아마 상속이었던걸로 기억합니다.
상속을 하면 자식도 싱글턴인가 모노인가 어쨌다던가 불라불라....
[url=http://c2.com/cgi/wiki?MonostatePat
여기에 잘 설명이 되어 있습니다.
----
I paint objects as I think them, not as I see them.
atie's minipage
댓글 달기