Whenever we think of Pattens we automatically home in on the GoF Design Patterns.
But there is more much more than just these patterns.
-
I will list all these Patterns which are relevant to us developers...
=============================================================
1. Enterprise Design Patterns:
=============================================================
Domain Logic Patterns: Transaction Script, Domain Model , Table Module, Service Layer.
Data Source Architectural Patterns: Table Data Gateway, Row Data Gateway, Active Record, Data Mapper.
Object-Relational Behavioral Patterns: Unit of Work, Identity Map, Lazy Load
Object-Relational Structural Patterns: Identity Field, Foreign Key Mapping, Association Table Mapping, Dependent Mapping, Embedded Value, Serialized LOB, Single Table Inheritance, Class Table Inheritance, Concrete Table Inheritance, Inheritance Mappers.
Object-Relational Metadata Mapping Patterns: Metadata Mapping, Query Object, Repository.
Web Presentation Patterns: Model View Controller, Page Controller, Front Controller, Template View, Transform View, Two-Step View, Application Controller.
Distribution Patterns: Remote Facade, Data Transfer Object
Offline Concurrency Patterns: Optimistic Offline Lock, Pessimistic Offline Lock, Coarse Grained Lock, Implicit Lock.
Session State Patterns: Client Session State, Server Session State, Database Session State.
Base Patterns: Gateway, Mapper, Layer Supertype, Separated Interface, Registry, Value Object, Money, Special Case, Plugin, Service Stub, Record Set
=====================================================================
2. Gof Design Patterns:
=====================================================================
Creational patterns
[Memorizing tips: ABFPS - Abraham Became the First President of States ]
Abstract factory : Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Builder : Separate the construction of a complex object from its representation allowing the same construction process to create various representations.
Factory method : Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses (dependency injection[18]).
Prototype : Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Yes No N/A
Singleton : Ensure a class has only one instance, and provide a global point of access to it.
---------------------------------------------Other Creational Patterns------------------------------
Lazy initialization : Tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed.
Multiton Ensure a class has only named instances, and provide global point of access to them.
Object pool : Avoid expensive acquisition and release of resources by recycling objects that are no longer in use. Can be considered a generalisation of connection pool and thread pool patterns.
Resource acquisition is initialization : Ensure that resources are properly released by tying them to the lifespan of suitable objects.
=====================================
Structural Patterns:
[Memorizing tips: : ABCD FFP]
Adapter or Wrapper or Translator: Convert the interface of a class into another interface clients expect. An adapter lets classes work together that could not otherwise because of incompatible interfaces. The enterprise integration pattern equivalent is the translator.
Bridge : Decouple an abstraction from its implementation allowing the two to vary independently.
Composite : Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Decorator : Attach additional responsibilities to an object dynamically keeping the same interface. Decorators provide a flexible alternative to subclassing for extending functionality.
Facade : Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
Flyweight : Use sharing to support large numbers of similar objects efficiently.
Proxy : Provide a surrogate or placeholder for another object to control access to it.
----------------------------Other Structural Patterns----------------------------------
Front Controller : The pattern relates to the design of Web applications. It provides a centralized entry point for handling requests.
Module : Group several related elements, such as classes, singletons, methods, globally used, into a single conceptual entity.
======================================
Behavioral Patterns:
[Memorizing tips: 2 MICS ON TV (MMIICCSSONTV)]
Chain of responsibility : Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
Command : Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
Interpreter : Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
Iterator : Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
Mediator : Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
Memento : Without violating encapsulation, capture and externalize an object's internal state allowing the object to be restored to this state later.
Observer or Publish/subscribe : Define a one-to-many dependency between objects where a state change in one object results in all its dependents being notified and updated automatically.
State : Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Strategy : Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Template method : Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
Visitor : Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
----------------------------Other behavioral patterns---------------------------------------------
Blackboard : Generalized observer, which allows multiple readers and writers. Communicates information system-wide.
Servant : Define common functionality for a group of classes
Null object : Avoid null references by providing a default object.
===========================================================
3. S.O.L.I.D. Principles: ( For Object-Oriented Designing)
==========================================================
S = SRP = The Single Responsibility Principle
Definition: There should never be more than one reason for a class to change.
Description: Basically, this means that your classes should exist for one purpose only. For example, let's say you are creating a class to represent a SalesOrder. You would not want that class to save to the database, as well as export an XML-based receipt. Why? Well if later on down the road, you want to change database type (or if you want to change your XML schema), you're allowing one responsibility's changes to possibly alter another. Responsibility is the heart of this principle, so to rephrase there should never be more than one responsibility per class.
Description from Wikipedia:
Every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.
For e.g., consider a module that compiles and prints a report. Such a module can be changed for two reasons. First, the content of the report can change. Second, the format of the report can change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times.
The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Continuing with the foregoing example, if there is a change to the report compilation process, there is greater danger that the printing code will break if it is part of the same class.
--------------------------------------------------------
O = OCP= The Open Closed Principle
Definition: Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
Description: At first, this seems to be contradictory: how can you make an object behave differently without modifying it? The answer: by using abstractions, or by placing behavior(responsibility) in derivative classes. In other words, by creating base classes with override-able functions, we are able to create new classes that do the same thing differently without changing the base functionality. Further, if properties of the abstracted class need to be compared or organized together, another abstraction should handle this. This is the basis of the "keep all object variables private" argument.
Description from wikipedia:
An entity can allow its behaviour to be modified without altering its source code. This is especially valuable in a production environment, where changes to source code may necessitate code reviews, unit tests, and other such procedures to qualify it for use in a product: code obeying the principle doesn't change when it is extended, and therefore needs no such effort.
--------------------------------------------------------
L = LSP = The Liskov Substitution Principle
Definition: “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”.
Description: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it. If you are calling a method defined at a base class upon an abstracted class, the function must be implemented properly on the subtype class. Or, "when using an object through its base class interface, [the] derived object must not expect such users to obey preconditions that are stronger than those required by the base class." The ever-popular illustration of this is the square-rectangle example. Turns out a square is not a rectangle, at least behavior-wise.
Description from wikipedia:
Liskov's notion of a behavioral subtype defines a notion of substitutability for mutable objects; that is, if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program (e.g., correctness).
Behavioral subtyping is a stronger notion than typical subtyping of functions defined in type theory, which relies only on the contravariance of argument types and covariance of the return type. Behavioral subtyping is trivially undecidable in general: if q is the property "method for x always terminates", then it is impossible for a program (e.g. a compiler) to verify that it holds true for some subtype S of T even if q does hold for T. The principle is useful however in reasoning about the design of class hierarchies.
--------------------------------------------------------
I = ISP = The Interface Segregation Principle
Definition: many client specific interfaces are better than one general purpose interface Description: Clients should not be forced to depend upon interfaces that they do not use. My favorite version of this is written as "when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class." Kinda sounds like the inheritance specific single responsibility principle.
Description from Wikipedia:
It is a software development principle used for clean development and intends to make software easy-to-change. ISP keeps a system decoupled and thus easier to refactor, change, and redeploy. ISP splits interfaces which are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them. In a nutshell, no client should be forced to depend on methods it does not use.[1] Such shrunken interfaces are also called role interfaces.[3]
-------------------------------------------------------- D = DIP = The Dependency Inversion Principle
Definition:
A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions. Description: Depend on abstractions, not on concretions or High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. (I like the first explanation the best.) This is very closely related to the open closed principle we discussed earlier. By passing dependencies (such as connectors to devices, storage) to classes as abstractions, you remove the need to program dependency specific. Here's an example: an Employee class that needs to be able to be persisted to XML and a database. If we placed ToXML() and ToDB() functions in the class, we'd be violating the single responsibility principle. If we created a function that took a value that represented whether to print to XML or to DB, we'd be hard-coding a set of devices and thus be violating the open closed principle. The best way to do this would be to:
1.Create an abstract class (named DataWriter, perhaps) that can be inherited from for XML (XMLDataWriter) or DB (DbDataWriter) Saving, and then
2.Create a class (named EmployeeWriter) that would expose an Output(DataWriter saveMethod) that accepts a dependency as an argument. See how the Output method is dependent upon the abstractions just as the output types are? The dependencies have been inverted. Now we can create new types of ways for Employee data to be written, perhaps via HTTP/HTTPS by creating abstractions, and without modifying any of our previous code! No rigidity--the desired outcome.
From wikipedia:
In conventional application architecture, lower-level components are designed to be consumed by higher-level components which enable increasingly complex systems to be built. In this composition, higher-level components depend directly upon lower-level components to achieve some task. This dependency upon lower-level components limits the reuse opportunities of the higher-level components.
The goal of the dependency inversion principle is to decouple high-level components from low-level components such that reuse with different low-level component implementations becomes possible. This is facilitated by the separation of high-level components and low-level components into separate packages/libraries, where interfaces defining the behavior/services required by the high-level component are owned by, and exist within the high-level component's package. The implementation of the high-level component's interface by the low level component requires that the low-level component package depend upon the high-level component for compilation, thus inverting the conventional dependency relationship. Various patterns such as Plugin, Service Locator, or Dependency Injection are then employed to facilitate the run-time provisioning of the chosen low-level component implementation to the high-level component.
Applying the dependency inversion principle can also be seen as applying the Adapter pattern, i.e. the high-level class defines its own adapter interface which is the abstraction that the high-level class depends on. The adaptee implementation also depends on the adapter interface abstraction (of course, since it implements its interface) while it can be implemented by using code from within its own low-level module. The high-level has no dependency to the low-level module since it only uses the low-level indirectly through the adapter interface by invoking polymorphic methods to the interface which are implemented by the adaptee and its low-level module.
--------------------------------------------------------------
Add-On to the SOLID Principles:
DRY = Dont repeat Yourself
Definition: "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."
Description: Don't Repeat Yourself (DRY) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures.
When the DRY principle is applied successfully, a modification of any single element of a system does not require a change in other logically unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync. Besides using methods and subroutines in their code, Thomas and Hunt rely on code generators, automatic build systems, and scripting languages to observe the DRY principle across layers.
============================================================
4. Microsoft Patterns Practices + The Enterprise Libraries
============================================================
http://msdn.microsoft.com/en-us/library/ff647095.aspx
Microsoft Enterprise Library / Application Blocks: The Microsoft Enterprise Library is a set of tools and programming libraries for the Microsoft .NET Framework. It provides an API to facilitate proven practices in core areas of programming including data access, security, logging, exception handling and others. Enterprise Library is provided as pluggable binaries and source code, which can be freely used and customized by developers for their own purposes.
Composite UI Application Block
============================================================
5. Message Exchange Patterns
============================================================
In software architecture, a messaging pattern is a network-oriented architectural pattern which describes how two different parts of a message passing system connect and communicate with each other.
In telecommunications, a message exchange pattern (MEP) describes the pattern of messages required by a communications protocol to establish or use a communication channel. There are two major message exchange patterns — a request-response pattern, and a one-way pattern. For example, the HTTP is a request-response pattern protocol, and the UDP has a one-way pattern.[1]
Acc. to ØMQ: ---------------------------------
Request-reply connects a set of clients to a set of services. This is a remote procedure call and task distribution pattern.[clarification needed]
Publish-subscribe connects a set of publishers to a set of subscribers. This is a data distribution pattern.[clarification needed]
Push-pull connects nodes in a fan-out / fan-in pattern that can have multiple steps, and loops. This is a parallel task distribution and collection pattern.[clarification needed]
Exclusive pair connects two sockets in an exclusive pair. This is a low-level pattern for specific, advanced use cases.
The term "Message Exchange Pattern" has a specific meaning within the SOAP protocol.[2][3] SOAP MEP types include:
Acc to SOAP:
--------------------------
1.In-Only: This is equivalent to one-way. A standard one-way messaging exchange where the consumer sends a message to the provider that provides only a status response.
2.Robust In-Only: This pattern is for reliable one-way message exchanges. The consumer initiates with a message to which the provider responds with status. If the response is a status, the exchange is complete, but if the response is a fault, the consumer must respond with a status.
3.In-Out: This is equivalent to request-response. A standard two-way message exchange where the consumer initiates with a message, the provider responds with a message or fault and the consumer responds with a status.
4.In Optional-Out: A standard two-way message exchange where the provider's response is optional.
5.Out-Only: The reverse of In-Only. It primarily supports event notification. It cannot trigger a fault message.
6.Robust Out-Only: similar to the out-only pattern, except it can trigger a fault message. The outbound message initiates the transmission.
7.Out-In: The reverse of In-Out. The provider transmits the request and initiates the exchange.
8.Out-Optional-In: The reverse of In-Optional-Out. The service produces an outbound message. The incoming message is optional ("Optional-in").
============================================================ 6. Reactive Framework:
============================================================
============================================================
7. Domain Driven Design:
============================================================
============================================================
8. Anti-Patterns:
============================================================
============================================================
9. Concurrency Patterns:
============================================================
This chapter presents five patterns that address various types of concurrency architecture and design issues for components, subsystems, and applications: Active Object, Monitor Object, Half-Sync/Half-Async, Leader/Followers, and Thread-Specific Storage.
The choice of concurrency architecture has a significant impact on the design and performance of multi-threaded networking middleware and applications. No single concurrency architecture is suitable for all workload conditions and hardware and software platforms. The patterns in this chapter therefore collectively provide solutions to a variety of concurrency problems.
The first two patterns in this chapter specify designs for sharing resources among multiple threads or processes:
•The Active Object design pattern decouples method execution from method invocation. Its purpose is to enhance concurrency and simplify synchronized access to objects that reside in their own threads of control
•The Monitor Object design pattern synchronizes concurrent method execution to ensure that only one method at a time runs within an object. It also allows an object's methods to schedule their execution sequences cooperatively.
Both patterns can synchronize and schedule methods invoked concurrently on objects. The main difference is that an active object executes its methods in a different thread than its clients, whereas a monitor object executes its methods by borrowing the thread of its clients. As a result active objects can perform more sophisticated--albeit expensive--scheduling to determine the order in which their methods execute.
The next two patterns in this chapter define higher-level concurrency architectures:
•The Half-Sync/Half-Async architectural pattern decouples asynchronous and synchronous processing in concurrent systems, to simplify programming without reducing performance undudly. This pattern introduces two intercommunicating layers, one for asynchronous and one for synchronous service processing. A queuing layer mediates communication between services in the asynchronous and synchronous layers.
•The Leader/Followers architectural pattern provides an efficient concurrency model where multiple threads take turns to share a set of event sources to detect, demultiplex, dispatch, and process service requests that occur on the event sources. The Leader/Followers pattern can be used in lieu of the Half-Sync/Half-Async and Active Object patterns to improve performance when there are no synchronization or ordering constraints on the processing of requests by pooled threads.
Implementors of the Half-Sync/Half-Async and Leader/Followers patterns can use the Active Object and Monitor Object patterns to coordinate access to shared objects efficiently.
The final pattern in this chapter offers a different strategy for addressing certain inherent complexities of concurrency:
•The Thread-Specific Storage design pattern allows multiple threads to use one `logically global' access point to retrieve an object that is local to a thread, without incurring locking overhead on each access to the object. To some extent this pattern can be viewed as the `antithesis' of the other patterns in this section, because it addresses several inherent complexities of concurrency by preventing the sharing of resources among threads.
Implementations of all patterns in this chapter can use the Synchronization patterns presented in Chapter 4 to protect critical regions from concurrent access.
============================================================ 10. Data Integration/SOA:
============================================================
But there is more much more than just these patterns.
-
I will list all these Patterns which are relevant to us developers...
=============================================================
1. Enterprise Design Patterns:
=============================================================
Domain Logic Patterns: Transaction Script, Domain Model , Table Module, Service Layer.
Data Source Architectural Patterns: Table Data Gateway, Row Data Gateway, Active Record, Data Mapper.
Object-Relational Behavioral Patterns: Unit of Work, Identity Map, Lazy Load
Object-Relational Structural Patterns: Identity Field, Foreign Key Mapping, Association Table Mapping, Dependent Mapping, Embedded Value, Serialized LOB, Single Table Inheritance, Class Table Inheritance, Concrete Table Inheritance, Inheritance Mappers.
Object-Relational Metadata Mapping Patterns: Metadata Mapping, Query Object, Repository.
Web Presentation Patterns: Model View Controller, Page Controller, Front Controller, Template View, Transform View, Two-Step View, Application Controller.
Distribution Patterns: Remote Facade, Data Transfer Object
Offline Concurrency Patterns: Optimistic Offline Lock, Pessimistic Offline Lock, Coarse Grained Lock, Implicit Lock.
Session State Patterns: Client Session State, Server Session State, Database Session State.
Base Patterns: Gateway, Mapper, Layer Supertype, Separated Interface, Registry, Value Object, Money, Special Case, Plugin, Service Stub, Record Set
=====================================================================
2. Gof Design Patterns:
=====================================================================
Creational patterns
[Memorizing tips: ABFPS - Abraham Became the First President of States ]
Abstract factory : Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Builder : Separate the construction of a complex object from its representation allowing the same construction process to create various representations.
Factory method : Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses (dependency injection[18]).
Prototype : Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Yes No N/A
Singleton : Ensure a class has only one instance, and provide a global point of access to it.
---------------------------------------------Other Creational Patterns------------------------------
Lazy initialization : Tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed.
Multiton Ensure a class has only named instances, and provide global point of access to them.
Object pool : Avoid expensive acquisition and release of resources by recycling objects that are no longer in use. Can be considered a generalisation of connection pool and thread pool patterns.
Resource acquisition is initialization : Ensure that resources are properly released by tying them to the lifespan of suitable objects.
=====================================
Structural Patterns:
[Memorizing tips: : ABCD FFP]
Adapter or Wrapper or Translator: Convert the interface of a class into another interface clients expect. An adapter lets classes work together that could not otherwise because of incompatible interfaces. The enterprise integration pattern equivalent is the translator.
Bridge : Decouple an abstraction from its implementation allowing the two to vary independently.
Composite : Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Decorator : Attach additional responsibilities to an object dynamically keeping the same interface. Decorators provide a flexible alternative to subclassing for extending functionality.
Facade : Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
Flyweight : Use sharing to support large numbers of similar objects efficiently.
Proxy : Provide a surrogate or placeholder for another object to control access to it.
----------------------------Other Structural Patterns----------------------------------
Front Controller : The pattern relates to the design of Web applications. It provides a centralized entry point for handling requests.
Module : Group several related elements, such as classes, singletons, methods, globally used, into a single conceptual entity.
======================================
Behavioral Patterns:
[Memorizing tips: 2 MICS ON TV (MMIICCSSONTV)]
Chain of responsibility : Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
Command : Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
Interpreter : Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
Iterator : Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
Mediator : Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
Memento : Without violating encapsulation, capture and externalize an object's internal state allowing the object to be restored to this state later.
Observer or Publish/subscribe : Define a one-to-many dependency between objects where a state change in one object results in all its dependents being notified and updated automatically.
State : Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Strategy : Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Template method : Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
Visitor : Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
----------------------------Other behavioral patterns---------------------------------------------
Blackboard : Generalized observer, which allows multiple readers and writers. Communicates information system-wide.
Servant : Define common functionality for a group of classes
Null object : Avoid null references by providing a default object.
===========================================================
3. S.O.L.I.D. Principles: ( For Object-Oriented Designing)
==========================================================
S = SRP = The Single Responsibility Principle
Definition: There should never be more than one reason for a class to change.
Description: Basically, this means that your classes should exist for one purpose only. For example, let's say you are creating a class to represent a SalesOrder. You would not want that class to save to the database, as well as export an XML-based receipt. Why? Well if later on down the road, you want to change database type (or if you want to change your XML schema), you're allowing one responsibility's changes to possibly alter another. Responsibility is the heart of this principle, so to rephrase there should never be more than one responsibility per class.
Description from Wikipedia:
Every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.
For e.g., consider a module that compiles and prints a report. Such a module can be changed for two reasons. First, the content of the report can change. Second, the format of the report can change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times.
The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Continuing with the foregoing example, if there is a change to the report compilation process, there is greater danger that the printing code will break if it is part of the same class.
--------------------------------------------------------
O = OCP= The Open Closed Principle
Definition: Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
Description: At first, this seems to be contradictory: how can you make an object behave differently without modifying it? The answer: by using abstractions, or by placing behavior(responsibility) in derivative classes. In other words, by creating base classes with override-able functions, we are able to create new classes that do the same thing differently without changing the base functionality. Further, if properties of the abstracted class need to be compared or organized together, another abstraction should handle this. This is the basis of the "keep all object variables private" argument.
Description from wikipedia:
An entity can allow its behaviour to be modified without altering its source code. This is especially valuable in a production environment, where changes to source code may necessitate code reviews, unit tests, and other such procedures to qualify it for use in a product: code obeying the principle doesn't change when it is extended, and therefore needs no such effort.
--------------------------------------------------------
L = LSP = The Liskov Substitution Principle
Definition: “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”.
Description: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it. If you are calling a method defined at a base class upon an abstracted class, the function must be implemented properly on the subtype class. Or, "when using an object through its base class interface, [the] derived object must not expect such users to obey preconditions that are stronger than those required by the base class." The ever-popular illustration of this is the square-rectangle example. Turns out a square is not a rectangle, at least behavior-wise.
Description from wikipedia:
Liskov's notion of a behavioral subtype defines a notion of substitutability for mutable objects; that is, if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program (e.g., correctness).
Behavioral subtyping is a stronger notion than typical subtyping of functions defined in type theory, which relies only on the contravariance of argument types and covariance of the return type. Behavioral subtyping is trivially undecidable in general: if q is the property "method for x always terminates", then it is impossible for a program (e.g. a compiler) to verify that it holds true for some subtype S of T even if q does hold for T. The principle is useful however in reasoning about the design of class hierarchies.
--------------------------------------------------------
I = ISP = The Interface Segregation Principle
Definition: many client specific interfaces are better than one general purpose interface Description: Clients should not be forced to depend upon interfaces that they do not use. My favorite version of this is written as "when a client depends upon a class that contains interfaces that the client does not use, but that other clients do use, then that client will be affected by the changes that those other clients force upon the class." Kinda sounds like the inheritance specific single responsibility principle.
Description from Wikipedia:
It is a software development principle used for clean development and intends to make software easy-to-change. ISP keeps a system decoupled and thus easier to refactor, change, and redeploy. ISP splits interfaces which are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them. In a nutshell, no client should be forced to depend on methods it does not use.[1] Such shrunken interfaces are also called role interfaces.[3]
-------------------------------------------------------- D = DIP = The Dependency Inversion Principle
Definition:
A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions. Description: Depend on abstractions, not on concretions or High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. (I like the first explanation the best.) This is very closely related to the open closed principle we discussed earlier. By passing dependencies (such as connectors to devices, storage) to classes as abstractions, you remove the need to program dependency specific. Here's an example: an Employee class that needs to be able to be persisted to XML and a database. If we placed ToXML() and ToDB() functions in the class, we'd be violating the single responsibility principle. If we created a function that took a value that represented whether to print to XML or to DB, we'd be hard-coding a set of devices and thus be violating the open closed principle. The best way to do this would be to:
1.Create an abstract class (named DataWriter, perhaps) that can be inherited from for XML (XMLDataWriter) or DB (DbDataWriter) Saving, and then
2.Create a class (named EmployeeWriter) that would expose an Output(DataWriter saveMethod) that accepts a dependency as an argument. See how the Output method is dependent upon the abstractions just as the output types are? The dependencies have been inverted. Now we can create new types of ways for Employee data to be written, perhaps via HTTP/HTTPS by creating abstractions, and without modifying any of our previous code! No rigidity--the desired outcome.
From wikipedia:
In conventional application architecture, lower-level components are designed to be consumed by higher-level components which enable increasingly complex systems to be built. In this composition, higher-level components depend directly upon lower-level components to achieve some task. This dependency upon lower-level components limits the reuse opportunities of the higher-level components.
The goal of the dependency inversion principle is to decouple high-level components from low-level components such that reuse with different low-level component implementations becomes possible. This is facilitated by the separation of high-level components and low-level components into separate packages/libraries, where interfaces defining the behavior/services required by the high-level component are owned by, and exist within the high-level component's package. The implementation of the high-level component's interface by the low level component requires that the low-level component package depend upon the high-level component for compilation, thus inverting the conventional dependency relationship. Various patterns such as Plugin, Service Locator, or Dependency Injection are then employed to facilitate the run-time provisioning of the chosen low-level component implementation to the high-level component.
Applying the dependency inversion principle can also be seen as applying the Adapter pattern, i.e. the high-level class defines its own adapter interface which is the abstraction that the high-level class depends on. The adaptee implementation also depends on the adapter interface abstraction (of course, since it implements its interface) while it can be implemented by using code from within its own low-level module. The high-level has no dependency to the low-level module since it only uses the low-level indirectly through the adapter interface by invoking polymorphic methods to the interface which are implemented by the adaptee and its low-level module.
--------------------------------------------------------------
Add-On to the SOLID Principles:
DRY = Dont repeat Yourself
Definition: "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."
Description: Don't Repeat Yourself (DRY) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures.
When the DRY principle is applied successfully, a modification of any single element of a system does not require a change in other logically unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync. Besides using methods and subroutines in their code, Thomas and Hunt rely on code generators, automatic build systems, and scripting languages to observe the DRY principle across layers.
============================================================
4. Microsoft Patterns Practices + The Enterprise Libraries
============================================================
http://msdn.microsoft.com/en-us/library/ff647095.aspx
Microsoft Enterprise Library / Application Blocks: The Microsoft Enterprise Library is a set of tools and programming libraries for the Microsoft .NET Framework. It provides an API to facilitate proven practices in core areas of programming including data access, security, logging, exception handling and others. Enterprise Library is provided as pluggable binaries and source code, which can be freely used and customized by developers for their own purposes.
Composite UI Application Block
============================================================
5. Message Exchange Patterns
============================================================
In software architecture, a messaging pattern is a network-oriented architectural pattern which describes how two different parts of a message passing system connect and communicate with each other.
In telecommunications, a message exchange pattern (MEP) describes the pattern of messages required by a communications protocol to establish or use a communication channel. There are two major message exchange patterns — a request-response pattern, and a one-way pattern. For example, the HTTP is a request-response pattern protocol, and the UDP has a one-way pattern.[1]
Acc. to ØMQ: ---------------------------------
Request-reply connects a set of clients to a set of services. This is a remote procedure call and task distribution pattern.[clarification needed]
Publish-subscribe connects a set of publishers to a set of subscribers. This is a data distribution pattern.[clarification needed]
Push-pull connects nodes in a fan-out / fan-in pattern that can have multiple steps, and loops. This is a parallel task distribution and collection pattern.[clarification needed]
Exclusive pair connects two sockets in an exclusive pair. This is a low-level pattern for specific, advanced use cases.
The term "Message Exchange Pattern" has a specific meaning within the SOAP protocol.[2][3] SOAP MEP types include:
Acc to SOAP:
--------------------------
1.In-Only: This is equivalent to one-way. A standard one-way messaging exchange where the consumer sends a message to the provider that provides only a status response.
2.Robust In-Only: This pattern is for reliable one-way message exchanges. The consumer initiates with a message to which the provider responds with status. If the response is a status, the exchange is complete, but if the response is a fault, the consumer must respond with a status.
3.In-Out: This is equivalent to request-response. A standard two-way message exchange where the consumer initiates with a message, the provider responds with a message or fault and the consumer responds with a status.
4.In Optional-Out: A standard two-way message exchange where the provider's response is optional.
5.Out-Only: The reverse of In-Only. It primarily supports event notification. It cannot trigger a fault message.
6.Robust Out-Only: similar to the out-only pattern, except it can trigger a fault message. The outbound message initiates the transmission.
7.Out-In: The reverse of In-Out. The provider transmits the request and initiates the exchange.
8.Out-Optional-In: The reverse of In-Optional-Out. The service produces an outbound message. The incoming message is optional ("Optional-in").
============================================================ 6. Reactive Framework:
============================================================
============================================================
7. Domain Driven Design:
============================================================
============================================================
8. Anti-Patterns:
============================================================
============================================================
9. Concurrency Patterns:
============================================================
This chapter presents five patterns that address various types of concurrency architecture and design issues for components, subsystems, and applications: Active Object, Monitor Object, Half-Sync/Half-Async, Leader/Followers, and Thread-Specific Storage.
The choice of concurrency architecture has a significant impact on the design and performance of multi-threaded networking middleware and applications. No single concurrency architecture is suitable for all workload conditions and hardware and software platforms. The patterns in this chapter therefore collectively provide solutions to a variety of concurrency problems.
The first two patterns in this chapter specify designs for sharing resources among multiple threads or processes:
•The Active Object design pattern decouples method execution from method invocation. Its purpose is to enhance concurrency and simplify synchronized access to objects that reside in their own threads of control
•The Monitor Object design pattern synchronizes concurrent method execution to ensure that only one method at a time runs within an object. It also allows an object's methods to schedule their execution sequences cooperatively.
Both patterns can synchronize and schedule methods invoked concurrently on objects. The main difference is that an active object executes its methods in a different thread than its clients, whereas a monitor object executes its methods by borrowing the thread of its clients. As a result active objects can perform more sophisticated--albeit expensive--scheduling to determine the order in which their methods execute.
The next two patterns in this chapter define higher-level concurrency architectures:
•The Half-Sync/Half-Async architectural pattern decouples asynchronous and synchronous processing in concurrent systems, to simplify programming without reducing performance undudly. This pattern introduces two intercommunicating layers, one for asynchronous and one for synchronous service processing. A queuing layer mediates communication between services in the asynchronous and synchronous layers.
•The Leader/Followers architectural pattern provides an efficient concurrency model where multiple threads take turns to share a set of event sources to detect, demultiplex, dispatch, and process service requests that occur on the event sources. The Leader/Followers pattern can be used in lieu of the Half-Sync/Half-Async and Active Object patterns to improve performance when there are no synchronization or ordering constraints on the processing of requests by pooled threads.
Implementors of the Half-Sync/Half-Async and Leader/Followers patterns can use the Active Object and Monitor Object patterns to coordinate access to shared objects efficiently.
The final pattern in this chapter offers a different strategy for addressing certain inherent complexities of concurrency:
•The Thread-Specific Storage design pattern allows multiple threads to use one `logically global' access point to retrieve an object that is local to a thread, without incurring locking overhead on each access to the object. To some extent this pattern can be viewed as the `antithesis' of the other patterns in this section, because it addresses several inherent complexities of concurrency by preventing the sharing of resources among threads.
Implementations of all patterns in this chapter can use the Synchronization patterns presented in Chapter 4 to protect critical regions from concurrent access.
============================================================ 10. Data Integration/SOA:
============================================================