0.1.33 • Published 6 years ago

design-patterns-core-api v0.1.33

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

design-patterns-core-api

Implementation of the 23 original ("Gang Of Four") Design Patterns as Interface classes (by means of mixin-interface-api).

ATM this framework provides 20 out of the 23 'Original Patterns' described by the Gang of Four in their 1995's book (Elements of Reusable Object-Oriented Software). There are further design patterns described later (e.g. Patterns of Enterprise Architecture Application written by Martin Fowler).

Your feedback (via GitHub) is welcome especially to report bugs or design issues, request for features or enhancements and contribute to the 'religious' aspects of this project, like which patterns are in fact Antipatterns or if it depends on the context (e.g. Singleton, Service Locator...).

Note about Design Issues

  • Craft a proposal for each pattern: there are many references about Design Patterns. My proposals should be not be taken as reference but more as an ongoing work (for which your feedback is welcome). Thus I advise you to study by yourself the references (I have gathered some of them in the References paragraph) to check it they fits your learning curve and your own design issues.
  • Resolve name conflicts across patterns: in the references, it happens that participant names (and operation names as well) are shared across patterns. In my proposals, I resolved these name conflicts either by mining in the references or by adding parent interface classes (e.g. IElement, IAction, _ICoreComponent...).

Release 0.1.33 changelog

  • Impact of Log feature refactoring (please find reference documentation here):
    • Implementation of Log feature redesigned and moved from mixin-interface to mixin-interface-api.
    • New Log API is MxI.$Log.write() (previously MxI.$System.log()) and MxI.$Log.addSink() (to set the target of trace requests).
    • Thus this package now directly depends from mixin-interface-api (and no more from mixin-interface).

Release 0.1.20 changelog

  • Design Issue: 'IProduct' interface is a misfit
  • Fix: Delete 'IProduct' move its 'getAttribute()' method in 'IElement' then update 'IProduct' dependents so that they depend on 'IElement' instead

Roadmap

  • UML class diagrams and implementation sample for each pattern

Preliminary notes

Naming convention: for any given interface class, its name is written with PascalCase convention (e.g. IAbstractFactory) and its source code uses snake_case convention (e.g. i_abstract_factory.js)

Why ...args ? Thanks to the rest parameter feature of javascript es6 (...args), most interface services accept optional and variable number of arguments.

What is the purpose of xxx_id arguments ? This is a design choice motivated by 2 design intents. The first is when the service call is propagated (e.g. 'requestid' argument is propagated by _Adapter when IAdapter.request() calls IAdaptee.specificRequest()). The second is to avoid counterproductive class proliferation by using xxx_id argument as a way to make the call more specific (e.g. 'requestid' argument when calling IHandler.handleRequest() within the _Chain Of Responsability pattern)

Creational patterns

Abstract Factory

Interface classes: IAbstractFactory, IElement.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Abstract Factory.
Abstract Factory UML model

Factory Method

Interface classes: I_Creator, IElement.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Factory Method.

Builder

Interface classes: IBuilder, IElement.
Detailed description: BlackWasp - Builder design pattern.

Singleton

Interface classes: MxI.$ISingleton.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Singleton.

Behavioral patterns

Observer

Interface classes: IObserver and IObservable.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Observer.
Observer UML model

Iterator

Interface classes: IIterator, ICollection.
Detailed description: Tutorials Point - Design Patterns: Iterator pattern.

State

Interface classes: IState, IStateContext.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - State.

Chain of Responsability

Interface classes: IHandler, IRequest.
Detailed description: OOODesign - Chain of Responsability.

Visitor

Interface classes: IVisitor, IElement.
Detailed description: Tutorials Point - Design Patterns: Visitor pattern.

Memento

Interface classes: IMemento, IOriginator, ICareTaker.
Detailed description: Tutorials Point - Design Patterns: Memento pattern.

Strategy

Interface classes: IStrategy, IStrategyContext.
Detailed description: Tutorials Point - Design Patterns: Strategy pattern.

Command

Interface classes: ICommand, IInvoker, IReceiver.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Command.

Template Method

Interface classes: ITemplateMethod.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Template Method.

Mediator

Interface classes: IMediator, IColleague, IRequest.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Mediator.

Structural patterns

Bridge

Interface classes: IImplementor.
Refer to Enginyeria del Software I - Curs 2006-2007 - Bridge.

Adapter

Interface classes: IAdapter, IAdaptee.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Adapter.

Facade

Interface classes: IFacade.
Detailed description: Tutorials Point - Design Patterns: Memento pattern.

Decorator

Interface classes: IDecorator, ICoreComponent.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Decorator.

Composite

Interface classes: IComponent, IComposite, ILeaf.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Composite.

Proxy

Interface classes: ISubject, IProxy.
Detailed description: Enginyeria del Software I - Curs 2006-2007 - Proxy.

Developer's Guide

How to implement a Design Pattern

A given Design Pattern is composed of one or more participants, this is very much like Role(s) in a play. Within design-patterns-api project, each participant is implemented as an interface classs. Thus, in order to implement a Design Pattern you must implement the interface class(es). Please refer to How to code an Implementation class in the documentation of mixin-interface-api package.

How to run the Unit Test

Step 1: Install Prerequisite Tools

Install NodeJS and Git

Step 2: Clone the 'design-patterns-core-api' repository locally

Open a command shell then enter the following commands:

git clone git://github.com/Echopraxium/design-patterns-core-api
cd design-patterns-core-api
npm update

Step 3: Run the Unit Test

Now enter the following command:

node test.js

You should get this kind of output (please find here the full output):

============================================================
===== Unit Test for 'design-patterns-core-api' package =====
============================================================
1. Creational Patterns
----------
1.1. Factory Method
----------
1.2. Builder
----------
1.1. Singleton
...
===================== End of Unit Test =====================

References

0.1.33

6 years ago

0.1.32

6 years ago

0.1.31

6 years ago

0.1.30

6 years ago

0.1.20

7 years ago

0.1.16

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.7

7 years ago

0.1.5

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.0

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago