Search Here!

Tuesday, April 20, 2010

Software Design Patterns & Christopher Alexander

The History of Software Design Patterns:
After spending some time researching what design patterns actually were, I found out that a professor in architecture from Berkley, launched the California answer to the problem of design complexity in 1977. This professor was Christoper Alexander. His theory was explained in three books: The Timeless Way of building (1979), A Pattern Language: Towns, Buildings, Construction (1977), and The Oregon Experiment (1975).

Patterns originated as an architectural notion by Christopher Alexander. So, what are patterns and their languages and what did Christopher Alexander have to do with this? Patterns and pattern languages for describing patterns are ways to explain good designs, describe best practices, and capture experience in a way that it is promising for others to reprocess this experience. In addition to the patterns, Alexander defined a set of rules e.g. a pattern language in which patterns could be meaningfully combined. Design pattern or computer science are extensively used by software engineers for the actual design process as well as for communicating a design to others.
According to an article on http://www.opensecurityarchitecture.org/cms/definitions/security_patterns,today we find patterns for many different areas in IT such as design patterns, architectural patterns and interaction design patterns but also security patterns. All these patterns use very similar pattern languages. It is interesting to observe how close all these pattern languages stick to the original language proposed by Christopher Alexander. The central argument of the Pattern Language is that, in the face of complexity, humans have evolved archetypal designs, which solve recurrent problems. These solutions are called patterns. In primitive societies, birds and humans had ways of using mud and grass to make dwellings. They remained constant from generation to generation. In modern societies, a greater range of patterns is available. Yet, the Pattern Language argues, there are still ways of doing things that, over an endless period of time, have satisfied complex human requirements. An ancient example is finding a choice location for an outdoor seat. Neglect of this pattern has led to a modern tragedy. Most outdoor seats in most towns are woefully sited: their locations are unprotected, isolated, noisy, windy, claustrophobic, too hot or too cold. The ancient pattern was to place a seat near a tree, with its back to a wall, in a sunny position with a good view (Figure 3.4). The archetype for this solution balances prospect with refuge. Jay Appleton, in The Experience of Landscape, sees this as a fundamental human need: it satisfies human desires for safety, comfort and a good vantage point ( Appleton, 1975). To avoid blunders, planners and designers must have this information.

Types of Design Patterns (http://geekexplains.blogspot.com/2008/09/design-patterns-types-and-suggested.html)

Design Patterns are divided into 3 categories:

Creational - the design patterns belonging to these category are used for creating objects. Using such a design pattern provides more flexibility where we require a control over the creation of objects. One very common use case is the usage of a creational design pattern to restrict the total number of instances of a class. Example: The Singleton Pattern, The Abstract Factory Method Pattern, etc

Structural - as the name suggests this category groups all those design patterns which help the user to group objects into larger structures to meet the complex requirements in a structured way. A common use case is to use such a design pattern for designing a complex user interface. Example: The Adapter Pattern, The Proxy Pattern, etc.



Behavioral - the patterns belonging to this category are used to define communication between objects of a proposed solution. In other words such design patterns helps defining the flow of a complex system. Example: The Chain of Responsibility Pattern, The Strategy Pattern, The Iterator Pattern, etc
Example of a Creational Design Pattern: The Abstract Factory Method Pattern

I found the following example from the A&P Web Consulting Company and easily understood the Abstract Factory Pattern through this page.
http://www.apwebco.com/gofpatterns/creational/FactoryMethod.html#example

Definition
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Class Diagram



Factory Method pattern is a simplified version of Abstract Factory pattern. Factory Method pattern is responsible of creating products that belong to one family, while Abstract Factory pattern deals with multiple families of products.
The official GoF Factory Method UML diagram (above) can be represented as in diagram below which uses the same terminology as Abstract Factory UML diagram:



Participants

Product
• defines the interface of objects the factory method creates.
ConcreteProduct
• implements the Product interface.
Creator
• declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object.
• may call the factory method to create a Product object.
ConcreteCreator
• overrides the factory method to return an instance of a ConcreteProduct
Benefits
• Eliminates the needs to bind application classes into your code. The code deals with interfaces so it can work with any classes that implement a certain interface.
• Enables the subclasses to provide an extended version of an object, because creating an object inside a class is more flexible than creating an object directly in the client.
Usage
• When a class cannot anticipate the class of objects it must create.
• When a class wants its subclasses to specify the objects it creates.
• Classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclasses is the delegate.

Here is another representation of the Abstract Factory Design Pattern:



References
[1] http://en.wikipedia.org/wiki/A_Pattern_Language
[2] http://natureoforder.com/library/scientific-introduction.pdf
[3] http://www.opengroup.org/security/gsp.htm
[4] http://www.securitypatterns.org
[5] http://www.gardenvisit.com/history_theory/library_online_ebooks/architecture_city_as_landscape/development_alexanders_pattern_language#ixzz0leOU2AYz

[6] http://www.apwebco.com/gofpatterns/creational/FactoryMethod.html
[7] http://geekexplains.blogspot.com/2008/09/design-patterns-types-and-suggested.html
[8] http://www.apwebco.com/gofpatterns/creational/FactoryMethod.html#example
[9] http://www.opensecurityarchitecture.org/cms/definitions/security_patterns

No comments:

Post a Comment