gang-of-four

Why does the builder pattern not have a method `GetResult()` in the builder interface?

吃可爱长大的小学妹 提交于 2019-12-13 01:45:51
问题 From Design Pattern by Gang of Four, Example: Why doesn't the interface Builder have a method GetResult() , which is overridden in the concrete class ConcreteBuilder ? In the example, the concrete builders have GetXXX() methods, where XXX is different for different concrete builders, which doesn't promote "programming to interface" at all. Is this "omission" deliberate in the builder pattern? 回答1: Yes, the omission is deliberate. The book addresses it directly. Why no abstract class for

What does “a class instantiates another” mean?

好久不见. 提交于 2019-12-11 17:06:47
问题 From Design Pattern by GoF: Another useful thing to show is which classes instantiate which others . We use a dashed arrowheaded line to indicate this, since OMT doesn't support it. We call this the "creates" relationship. The arrow points to the class that's instantiated. In Figure B.lc, CreationTool creates LineShape objects. What does "a class instantiates another" mean here? Thanks. 回答1: Another way to phrase it would be "a class creates an instance of another", which makes it a little

Why do the references in a decorator and in a proxy point to their subject's interface and concrete respectively?

点点圈 提交于 2019-12-11 10:58:55
问题 From Design Pattern by Gang of Four Why does the reference component of the decorator Decorator to the decorated point to the interface Component of the decorated, while the reference realSubject of the proxy Proxy point to the concrete RealSubject ? Thanks. 回答1: Proxy may point exclusively to its subject's interface. The GoF mentions, Proxy may refer to a Subject if the RealSubject and Subject interfaces are the same. But depending on implementation, a Proxy may instantiate its subject by

What are the purposes of other members of a Singleton class besides the instance and its get method?

让人想犯罪 __ 提交于 2019-12-11 10:48:38
问题 From Design Pattern by GoF Participants • Singleton defines an Instance operation that lets clients access its unique instance uniqueinstance . Instance is a class operation (that is, a class method in Smalltalk and a static member function in C++). may be responsible for creating its own unique instance uniqueinstance . Collaborations • Clients access a Singleton instance uniqueinstance solely through Singleton 's Instance operation. In Class Singleton , uniqueinstance is the unique instance

Are these both the abstract factory pattern?

北城以北 提交于 2019-12-10 18:49:10
问题 I think the original use of the abstract factory pattern is when you want to create a family of related objects. This is what is described in Gang of Four (GoF) and this tutorial: http://www.oodesign.com/abstract-factory-pattern.html I keep also seeing posts that the abstract factory pattern can be used for dependency injection, particulary for injecting values that are worked out at runtime. All the uses of abstract factory pattern given here seem to be referring to this method: Why do we

Singleton pattern in JavaScript

一世执手 提交于 2019-12-03 12:38:40
问题 Below is an example of a very popular implementation of the JavaScript Singleton pattern: var mySingleton = (function() { var instance; function init() { function privateMethod() { console.log("I am private"); } var privateVariable = "Im also private"; var privateRandomNumber = Math.random(); return { publicMethod: function() { console.log("The public can see me!"); }, publicProperty: "I am also public", getRandomNumber: function() { return privateRandomNumber; } }; }; return { getInstance: