-
Notifications
You must be signed in to change notification settings - Fork 3
Home
All patterns are constructed on the go and can be wrapped around each other (see advance topics). All the patterns take in an optional options object that is used to create the pattern. The patterns return a builder object which is used to build the pattern class OR by other patterns for advanced functionality.
I realize that the pattern implementations in this library are very shallow and basic but that is the idea, something simple and trustworthy.
-
constructor [Function] (optional)
- used as a constructor for when creating a new instance of the pattern.
- note: although some transpilers will make it work, arrow functions and method definitions do not work as they do not have a
prototype
property.
-
publics [Object] (optional)
- methods or props that will be appended as the prototype of the pattern constructor.
- all new instances of the pattern will have access to anything defined within the object.
- when wrapping patterns (see advanced functionality) the publics object is applied to the outermost pattern prototype only.
-
statics [Object] (optional)
- same as publics but everything within this object will be appended to the constructor rather than the prototype.
- when wrapping patterns (see advanced functionality) the statics object is applied to the outermost pattern constructor only.
var options = {
constructor: function() {},
publics: {},
statics: {}
};
var Pattern = pattern(options).build();
var instance = new Pattern();
Before we begin, please feel free to contribute to the core library as I'm open to any constructive ideas to improve it. That means, if the wiki is wrong, or you want to add a new pattern, or you have questions, or if you believe that a pattern is incorrect, could be simplified even further, could be improved, needs some fixes, or it is entirely wrong, please create an issue and/or PR.
Now, there are multiple examples (usually 3) per pattern, the examples are based on made up problems which can be exaggerated or simplified to function as mere illustrations on how to use each of the features of the pattern at hand and the go-patterns library. In other words, the example might not be a real-life solution for the problem illustrated.
Creational design patterns focus on handling object creation mechanisms where objects are created in a manner suitable for the situation we're working in. The basic approach to object creation might otherwise lead to added complexity in a project whilst these patterns aim to solve this problem by controlling the creation process.
Some of the patterns that fall under this category are Constructor, Factory, Abstract, Prototype, Singleton, and Builder.
Behavioral patterns focus on improving or streamlining the communication between disparate objects in a system.
Some behavioral patterns include Iterator, Mediator, Observer, and Visitor.
Structural patterns are concerned with object composition and typically identify simple ways to realize relationships between different objects. They help ensure that when one part of a system changes, the entire structure of the system doesn't need to do the same. They also assist in recasting parts of the system which don't fit a particular purpose into those that do.
Patterns that fall under this category include Decorator, Facade, Flyweight, Adapter, and Proxy.
The book does not provide a definition of architectural patterns, so here is a paraphrased sentence:
Architectural design patterns encourage improved application organization through a separation of concerns.
I believe creating a single pattern for each of them is difficult to abstract, so I created an MVW pattern that behaves almost exclusively like an MVVM pattern, except that you can modify its behavior.
Abstracting the patterns can have drawbacks as is the fact that not every pattern implementation in this library will be attractive to you or behave the way you want them to behave.
I designed this library thinking in future aggregations and enhancements by simply making the core functionality available from the outside. This way you can build your own patterns or improve the ones that are already there.