<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aasawa</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aasawa"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Aasawa"/>
	<updated>2026-09-27T22:30:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71020</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71020"/>
		<updated>2012-11-20T01:26:45Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter Sourcemaking - Adapter Design Pattern  - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern&amp;lt;ref&amp;gt;Freeman,E., and Robson,E.,and Bates,B.,and Sierra,K. 2004. Head First Design Patterns&amp;lt;/ref&amp;gt; provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern&amp;lt;ref&amp;gt;Erich,G., and Richard,H.,and Ralph,J.,and John,M.V. 1997. Design Patterns: Elements of Reusable Object-Oriented Software&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Pattern] at Wikipedia&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Facade_pattern Facade Design Pattern] at Wikipedia&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71019</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71019"/>
		<updated>2012-11-20T01:26:23Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter Sourcemaking - Adapter Design Pattern  - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern&amp;lt;ref&amp;gt;Freeman,E., and Robson,E.,and Bates,B.,and Sierra,K. 2004. Head First Design Patterns&amp;lt;/ref&amp;gt; provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern&amp;lt;ref&amp;gt;Erich,G., and Richard,H.,and Ralph,J.,and John,M.V. 1997. Design Patterns: Elements of Reusable Object-Oriented Software&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Pattern] at Wikipedia&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Facaed_pattern Facade Design Pattern] at Wikipedia&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71018</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71018"/>
		<updated>2012-11-20T01:23:56Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter Sourcemaking - Adapter Design Pattern  - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern&amp;lt;ref&amp;gt;Freeman,E., and Robson,E.,and Bates,B.,and Sierra,K. 2004. Head First Design Patterns&amp;lt;/ref&amp;gt; provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern&amp;lt;ref&amp;gt;Erich,G., and Richard,H.,and Ralph,J.,and John,M.V. 1997. Design Patterns: Elements of Reusable Object-Oriented Software&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71017</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71017"/>
		<updated>2012-11-20T01:23:22Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Differences and similarities between Facade and Abstract Factory patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter Sourcemaking - Adapter Design Pattern  - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern&amp;lt;ref&amp;gt;Freeman,E., and Robson,E.,and Bates,B.,and Sierra,K. 2004. Head First Design Patterns&amp;lt;/ref&amp;gt; provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern&amp;lt;ref&amp;gt;Erich,G., and Richard,H.,and Ralph,J.,and John,M.V. 1997. Design Patterns: Elements of Reusable Object-Oriented Software&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71016</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71016"/>
		<updated>2012-11-20T01:22:36Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter Sourcemaking - Adapter Design Pattern  - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern&amp;lt;ref&amp;gt;Freeman,E., and Robson,E.,and Bates,B.,and Sierra,K. 2004. Head First Design Patterns&amp;lt;/ref&amp;gt; provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71014</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71014"/>
		<updated>2012-11-20T01:21:12Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter Sourcemaking - Adapter Design Pattern  - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71011</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71011"/>
		<updated>2012-11-20T01:19:43Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Adapter Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter Sourcemaking - Adapter Design Pattern  - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71008</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71008"/>
		<updated>2012-11-20T01:18:31Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Adapter Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intenthttp://sourcemaking.com/design_patterns/adapter&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71004</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71004"/>
		<updated>2012-11-20T01:16:23Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Differences and similarities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern Scribd - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71003</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71003"/>
		<updated>2012-11-20T01:15:26Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Differences and similaritieshttp://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior&amp;lt;ref&amp;gt;[http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern ASPAlliance - Facade Design Pattern  - http://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern]&amp;lt;/ref&amp;gt;  in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71002</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71002"/>
		<updated>2012-11-20T01:13:46Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Differences and similarities */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similaritieshttp://www.scribd.com/doc/2283673/Design-patterns-the-facade-and-adapter-pattern ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71001</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71001"/>
		<updated>2012-11-20T01:13:06Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
* [http://www.coderanch.com/t/99780/patterns/Factory-Abstract-Factory-Pattern Facade &lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70998</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70998"/>
		<updated>2012-11-20T01:10:41Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-uncovered-1 Facade Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern.html difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
&lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70995</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70995"/>
		<updated>2012-11-20T01:09:14Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-command Command Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
* [http://stackoverflow.com/questions/11188869/what-is-the-differences-between-facade-pattern-and-abstarct-factory-pattern&lt;br /&gt;
   difference between facade and abstract factory pattern] at stackoverflow.com&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
&lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70992</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70992"/>
		<updated>2012-11-20T01:06:49Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.codeproject.com/Articles/15207/Design-Patterns-Command-Pattern Design Pattern: Command Pattern] at codeproject.com&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-command Command Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternFacade.aspx Facade Pattern] at dofactory.com&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
&lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70989</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70989"/>
		<updated>2012-11-20T01:06:02Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.codeproject.com/Articles/15207/Design-Patterns-Command-Pattern Design Pattern: Command Pattern] at codeproject.com&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-command Command Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern] at dofactory.com&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
&lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w52_an&amp;diff=70985</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w52 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w52_an&amp;diff=70985"/>
		<updated>2012-11-20T01:04:50Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: Undo revision 70983 by Aasawa (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Command Pattern ''' ==&lt;br /&gt;
&lt;br /&gt;
Command Pattern is a [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) design pattern] in [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] in which an object is used to represent and [http://en.wikipedia.org/wiki/Encapsulation_(computer_science)#Encapsulation encapsulate] all the information needed to call a method at a later time. This information comprises of, the method name, the object that is the owner of the method and values for the method parameters. It encapsulates a request as an object and gives it a known public interface. It ensures that every object receives its own commands and provides a [http://en.wikipedia.org/wiki/Decoupling#Software_Development decoupling] between sender and receiver. In this case a sender is an object that invokes an operation, and a receiver is an object that receives the request and acts on it.&lt;br /&gt;
&lt;br /&gt;
There are three main components of a Command pattern: the ''Invoker'', the ''Command'', and the ''Receiver''. The invoker component acts as a link between the commands and the receiver, and houses the receiver and the individual commands as they are sent. The command is an object that encapsulates a request to the receiver. The receiver is the component that is acted upon by each request.&lt;br /&gt;
&lt;br /&gt;
The intent of using command objects is to easily construct the general components that need to sequence, delegate or execute method calls at a time of their choosing without the need to know the owner of the method or the method parameters. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
Developers might use a switch statement with a case for each command. Usage of Switch statements during coding is a sign of bad design during the design phase of an object-oriented project. Commands represent an object-oriented way to support transactions&amp;lt;ref&amp;gt;[http://www.oodesign.com/command-pattern.html Oodesign. (2005-2006)- command-pattern - http://www.oodesign.com/command-pattern.html]&amp;lt;/ref&amp;gt; and can be used to solve this design problem.&lt;br /&gt;
&lt;br /&gt;
== Why and When do we use a Command Pattern? ==&lt;br /&gt;
Command Pattern comes into picture when there is a need  to store objects behaviour as a command and its state. The Command pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are several benefits&amp;lt;ref&amp;gt;[http://www.javaworld.com/javaworld/jw-06-2002/jw-0628-designpatterns.html Javaworld - Command Design Pattern  - http://www.javaworld.com/javaworld/jw-06-2002/jw-0628-designpatterns.html]&amp;lt;/ref&amp;gt; of using the Command pattern:&lt;br /&gt;
&lt;br /&gt;
* It provides encapsulation of application logic so that it can be executed at a different point of time.&lt;br /&gt;
&lt;br /&gt;
* It allows to execute the application in separate contexts, such as in a different thread or using a different state by separating the application logic and context.&lt;br /&gt;
&lt;br /&gt;
* The separation between application logic and context allows to easier exchange the application logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command Patterns can be used for the following:&lt;br /&gt;
&lt;br /&gt;
'''Undo and redo actions'''&lt;br /&gt;
&lt;br /&gt;
There is support for undo and redo of actions in certain implementations of the Command design pattern. In order to do that, a mechanism to obtain past states of the Receiver object is needed; there are two options to achieve this:&lt;br /&gt;
* Before running each command a snapshot of the receiver state is stored in memory. This does not require much programming effort but can not be always applied. For example doing this in an image processing application would require storing images in memory after each step, which is practically impossible. &lt;br /&gt;
* Instead of storing receiver objects states, the set of performed operations are stored in memory. In this case the command and receiver classes should implement the inverse algorithms to undo each action. This will require additional programming effort, but less memory will be required. Sometimes for undo/redo actions the command should store more information about the state of the receiver objects. A good idea in such cases is to use the [http://en.wikipedia.org/wiki/Memento_pattern Memento Pattern].&lt;br /&gt;
&lt;br /&gt;
'''Asynchronous Method Invocation'''&lt;br /&gt;
&lt;br /&gt;
Another usage for the command design pattern is to run commands asynchronous in background of an application. In this case the invoker is running in the main thread and sends the requests to the receiver which is running in a separate thread. The invoker will keep a queue of commands to be run and will send them to the receiver while it finishes running them.&lt;br /&gt;
&lt;br /&gt;
Instead of using one thread in which the receiver is running more threads can be created for this. But for performance issues (thread creation is consuming) the number of threads should be limited. In this case the invoker will use a pool of receiver threads to run command asynchronously.&lt;br /&gt;
&lt;br /&gt;
'''Adding new commands'''&lt;br /&gt;
&lt;br /&gt;
The command object decouples the object that invokes the action from the object that performs the action. There are implementations of the pattern in which the invoker instantiates the concrete command objects. In this case if we need to add a new command type we need to change the invoker as well. And this would violate the Open Close Principle (OCP). In order to have the ability to add new commands with minimum of effort we have to make sure that the invoker is aware only about the abstract command class or interface.&lt;br /&gt;
&lt;br /&gt;
'''Using composite commands'''&lt;br /&gt;
&lt;br /&gt;
When adding new commands to the application we can use the [http://en.wikipedia.org/wiki/Composite_pattern composite pattern] to group existing commands in another new command. This way, macros can be created from existing commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
There are many applications&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Command_pattern Wikipedia. (2010, October) Wikipedia - Command_Pattern - http://en.wikipedia.org/wiki/Command_pattern]&amp;lt;/ref&amp;gt; that make use of command pattern.Command objects are useful for implementing:&lt;br /&gt;
&lt;br /&gt;
; In Networking : In case of computer games,player actions can to send whole command objects across the network to be executed on the other machines.&lt;br /&gt;
; In parallel processing : In parallel processing, tasks may be referred as the commands to a shared resource. These tasks will be executed by many threads in parallel.This can be considered as a Client/Server model.&lt;br /&gt;
; Graphical User Interface buttons: An [http://docs.oracle.com/javase/7/docs/api/javax/swing/Action.html Action] is a command object in case of [http://en.wikipedia.org/wiki/Swing_(Java) Swings]. A submit button, menu button or checkbox button component may be completely initialized using only the &amp;lt;code&amp;gt;Action&amp;lt;/code&amp;gt; object. In a given scenario,an Action may have an icon bound to it ,mouse click,a keyboard shortcut in addition to the ability to perform the desired command.&lt;br /&gt;
; Multi-level [http://en.wikipedia.org/wiki/Undo undo] : The program can keep a stack of the most recently executed commands if all user actions in a program are implemented as command objects. The program simply pops the most recent command object and executes its &amp;lt;tt&amp;gt;undo()&amp;lt;/tt&amp;gt; method when the user wants to undo a command.&lt;br /&gt;
; [http://en.wikipedia.org/wiki/Database_transaction Transactional behavior of Databases] : A database engine or software installer may keep a list of operations that have been or will be performed similar to undo.All others can be reverted or discarded if one of them fail. For instance, if two database tables that refer to each other must be updated, and the second update fails, the transaction can be rolled back, so that the first table does not now contain an invalid reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Components of a command pattern ==&lt;br /&gt;
The various components&amp;lt;ref&amp;gt;Freeman,E., and Robson,E.,and Bates,B.,and Sierra,K. 2004. Head First Design Patterns&amp;lt;/ref&amp;gt; of a command pattern are given as follows:&lt;br /&gt;
&lt;br /&gt;
'''Client:''' Invokes a particular module using a command and passes a request which gets propagated as a command.&lt;br /&gt;
&lt;br /&gt;
'''Command:''' It is an object that encapsulates a request to the receiver. Command request maps to particular modules. According to the command, a module is invoked.&lt;br /&gt;
&lt;br /&gt;
'''Receiver:''' It is the component that is acted upon by each request. It knows how to perform the operations associated with carrying out a certain request.&lt;br /&gt;
&lt;br /&gt;
'''Invoker:''' It is the class that is invoked by the client. It takes in the request and calls the receiver by passing the command to it and asks it to carry out the request.&lt;br /&gt;
&lt;br /&gt;
'''Concrete Command:''' It defines a link between the receiver and the action. It basically implements the execute method and invokes the corresponding operations on the receiver.&lt;br /&gt;
&lt;br /&gt;
Throughout this page, we will discuss the example of an operation of converting a string into either upper case or lower case. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:WIKI.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The components corresponding to the example are given in the figure above. From the figure we can identify the components as follows: &lt;br /&gt;
&lt;br /&gt;
'''Client:''' Menu Class is used to set the ConcreteCommand and then sets the convert class &lt;br /&gt;
&lt;br /&gt;
'''Command:''' Command Class in this case is declaring the interface which is used to execute the operation.&lt;br /&gt;
&lt;br /&gt;
'''Receiver:''' Convert Class is the one which knows how to perform the operations.&lt;br /&gt;
&lt;br /&gt;
'''Invoker:'''  TextOperation Class asks the command to carry out the action which in this case is to either convert toUpper or toLower.&lt;br /&gt;
&lt;br /&gt;
'''ConcreteCommand:''' ConvertUpper, ConvertLower classes are the ones that implement the execute command.&lt;br /&gt;
&lt;br /&gt;
==Terminology==&lt;br /&gt;
&lt;br /&gt;
The terminology used to describe command pattern implementations can be confusing sometimes.&lt;br /&gt;
* '''Command Object, Routed Command Object and Action Object''': In this, we can refer a singleton object which knows about mouse click , button images, shortcut keys and so on related to the command. A invoker object calls the Action object's performAction method.When the availability of a command/action has changed, the Command/Action object notifies the appropriate source/invoker objects.When a command/action cannot be executed/performed, this allows buttons and menu items to become inactive.&lt;br /&gt;
* '''Client, Source and Invoker''': It refers to a button, toolbar button, or radio button clicked, or the shortcut key pressed by the user.&lt;br /&gt;
* '''Receiver, Target Object''': This is the object that is about will be copied, pasted or perform some other function . The receiver object owns the method that is called by the command's ''execute'' method. The receiver is  also the target object. For instance, if the receiver object is a ''cursor'' and the method is called ''moveDown'', then one would expect that the cursor is the target of the moveDown action.&lt;br /&gt;
* '''Handler, method, ''': This is the actual code that does the copying, pasting  etc.There are many variants of the handler. This is the handler code of the action object in some implementations. In other implementations the code is part of the Receiver/Target Object.Finally in some other implementations the handler code is kept separate from the other objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Check list for Command Pattern Implementation ==&lt;br /&gt;
&lt;br /&gt;
* Define a Command interface with a method signature like &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Create one or more derived classes that encapsulate some subset of the following: a “receiver” object, the method to invoke, the arguments to pass.&lt;br /&gt;
* Instantiate a Command object for each deferred execution request.&lt;br /&gt;
* Pass the Command object from the creator (aka sender) to the invoker (aka receiver).&lt;br /&gt;
* The invoker decides when to &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Rules of thumb&amp;lt;ref&amp;gt;Erich,G., and Richard,H.,and Ralph,J.,and John,M.V. 1997. Design Patterns: Elements of Reusable Object-Oriented Software&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], Command, [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], and [http://en.wikipedia.org/wiki/Observer_pattern Observer], address how you can decouple senders and receivers, but with different trade-offs. *Command normally specifies a sender-receiver connection with a subclass.&lt;br /&gt;
*Chain of Responsibility can use Command to represent requests as objects.&lt;br /&gt;
*Command and Memento act as magic tokens to be passed around and invoked at a later time. In Command, the token represents a request; in *Memento, it represents the internal state of an object at a particular time. Polymorphism is important to Command, but not to Memento because its interface is so narrow that a memento can only be passed as a value.&lt;br /&gt;
*Command can use Memento to maintain the state required for an undo operation.&lt;br /&gt;
*MacroCommands can be implemented with Composite.&lt;br /&gt;
*A Command that must be copied before being placed on a history list acts as a Prototype.&lt;br /&gt;
*Two important aspects of the Command pattern: interface separation (the invoker is isolated from the receiver), time separation (stores a ready-to-go processing request that’s to be stated later).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example of Command pattern ==&lt;br /&gt;
&lt;br /&gt;
Consider the case of converting a string to upper and lower case.The Client is the Menu where we see the options. The menu sends the request to the receiver(convert class) through the Invoker(TextOperations class). The textOperation encapsulates the command and then forwards it, creating the ConcreteCommand object which is the command itself. The Receiver will be the Convert class that, after completing all the commands that were sent to it before the command in question(to Upper case or to lower case ), starts to work on it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation in static and dynamic languages ==&lt;br /&gt;
&lt;br /&gt;
=== Implementation in Static languages ===&lt;br /&gt;
We initially define a Command interface with a method named execute() and then we create command classes that implement this interface. The execute() method of each object will contain the logic specific to the action you are encapsulating. &lt;br /&gt;
(For instance, you might create a convertUpper and a converLower command in a text editor application.)&lt;br /&gt;
&lt;br /&gt;
In case of the static implementation, code snippets to implement the command pattern in languages like Java and C# are given as follows:&lt;br /&gt;
&lt;br /&gt;
==== Java Example ====&lt;br /&gt;
This contains the '''Command interface''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create command classes that implement this interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public interface Command{&lt;br /&gt;
     void execute();&lt;br /&gt;
 }&lt;br /&gt;
 //A command to convert to lower case.&lt;br /&gt;
 public class convertLower implements Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertLower(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toLower();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
//A command to convert to upper case&lt;br /&gt;
 public class convertUpper implements Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertUpper(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toUpper();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''invoker class''' which contains the method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class TextOperations{&lt;br /&gt;
    private ArrayList&amp;lt;Command&amp;gt; Command_List= new ArrayList&amp;lt;Command&amp;gt;;&lt;br /&gt;
        private TextOperations(){&lt;br /&gt;
        }&lt;br /&gt;
        public void commandExecute(Command cmd){&lt;br /&gt;
        this.Command_List.add(cmd); // optional &lt;br /&gt;
         cmd.execute();     &lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class Convert{&lt;br /&gt;
    public Convert(){&lt;br /&gt;
    }&lt;br /&gt;
    public final void toUpper(){&lt;br /&gt;
        System.out.print(&amp;quot;Turning all lower case elements to upper case&amp;quot;);//The actual action that is being performed.&lt;br /&gt;
    }&lt;br /&gt;
    public final void toLower(){&lt;br /&gt;
        System.out.print(&amp;quot;Converting all upper case elements to lower case&amp;quot;);//The actual action that is being performed.&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class Menu{&lt;br /&gt;
   public static void main(String[] args){&lt;br /&gt;
      Convert c = new Convert();&lt;br /&gt;
      Command conToUpper = new convertUpper(c);&lt;br /&gt;
      Command conToLower = new convertLower(c);&lt;br /&gt;
 &lt;br /&gt;
      TextOperations converter = new TextOperations(); &lt;br /&gt;
         if (args[0].equalsIgnoreCase(&amp;quot;ToUpper&amp;quot;)) {&lt;br /&gt;
            converter.commandExecute(conToUpper);&lt;br /&gt;
            System.exit(0);&lt;br /&gt;
         }&lt;br /&gt;
         if (args[0].equalsIgnoreCase(&amp;quot;ToLower&amp;quot;)) {&lt;br /&gt;
            converter.commandExecute(conToLower);&lt;br /&gt;
            System.exit(0);&lt;br /&gt;
         }       &lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== C# Example ====&lt;br /&gt;
This contains the '''Command interface''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create command classes that implement this interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public interface Command&lt;br /&gt;
 {&lt;br /&gt;
     void execute(); //The execute method that is going to call the action&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 //A command to convert to lower case.&lt;br /&gt;
 public class convertLower : Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertLower(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toLower();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 //A command to convert to upper case&lt;br /&gt;
 public class convertUpper : Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertUpper(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toUpper();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
This is the '''invoker class''' which contains method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as the parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class TextOperations{&lt;br /&gt;
    private ArrayList&amp;lt;Command&amp;gt; _command_List= new ArrayList&amp;lt;Command&amp;gt;;&lt;br /&gt;
        private TextOperations(){&lt;br /&gt;
        }&lt;br /&gt;
        public void commandExecute(Command cmd){&lt;br /&gt;
        _commands.add(cmd); // optional &lt;br /&gt;
         cmd.execute();     &lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
 public class Convert{&lt;br /&gt;
    public Convert(){&lt;br /&gt;
    }&lt;br /&gt;
    public final void toUpper(){&lt;br /&gt;
        Console.WriteLine(&amp;quot;Turning all lower case elements to upper case&amp;quot;);// These are the actual actions that are performed&lt;br /&gt;
    }&lt;br /&gt;
    public final void toLower(){&lt;br /&gt;
        Console.WriteLine(&amp;quot;Converting all upper case elements to lower case&amp;quot;); //These is the actual action that is performed&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class Menu&lt;br /&gt;
 {&lt;br /&gt;
    Static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        Convert c = new Convert();&lt;br /&gt;
        Command conToUpper = new convertUpper(c);&lt;br /&gt;
        Command conToLower = new convertLower(c);&lt;br /&gt;
        TextOperations converter = new TextOperations(); /*Client calls the invoker and gives the commands to execute*/&lt;br /&gt;
                if (args[0].ToUpper().Equals(&amp;quot;toUpper&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    converter.commandExecute(conToUpper);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
                if (args[0].ToUpper().Equals(&amp;quot;tolower&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    converter.commandExecute(conToLower);&lt;br /&gt;
                    return;&lt;br /&gt;
                }               &lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Implementation in Dynamic Languages ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic languages] we will have a controller class that constructs each of the Command objects.Each of these command objects is passed to an invoker class. The invoker class calls the execute() method of a Command object at the appropriate time. &lt;br /&gt;
(For instance this may happen when a user selects a menu item or presses a button)&lt;br /&gt;
&lt;br /&gt;
In case of the dynamic languages, the code snippets to implement command pattern for ruby and python are given as follows.&lt;br /&gt;
&lt;br /&gt;
==== Ruby Example ====&lt;br /&gt;
This contains the '''Command class''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create derived classes that inherit from the Command class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Command&lt;br /&gt;
 	def execute()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
 class convertLower &amp;lt; Command&lt;br /&gt;
 	def initialize(conv)&lt;br /&gt;
 		self.@convert = conv&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def execute()&lt;br /&gt;
 		@convert.toLower()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
 class convertUpper &amp;lt; Command&lt;br /&gt;
 	def initialize(conv)&lt;br /&gt;
 		self.@convert = conv&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def execute()&lt;br /&gt;
 		@convert.toUpper()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Convert&lt;br /&gt;
 	def initialize()&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def toUpper()&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Turning all lower case elements to upper case&amp;quot;)&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def toLower()&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Converting all upper case elements to lower case&amp;quot;)&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''invoker class''' which contains the method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class TextOperations&lt;br /&gt;
 	def initialize(toup, todwn)&lt;br /&gt;
 		self.@convertUp = toup&lt;br /&gt;
 		self.@convertLow = todwn&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def convToUp()&lt;br /&gt;
 		@convertUp.execute()&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def convToLow()&lt;br /&gt;
 		@convertLow.execute()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Menu&lt;br /&gt;
 	def Main(args)&lt;br /&gt;
 		c = Convert.new()&lt;br /&gt;
 		cou = convertUpper.new(c)&lt;br /&gt;
 		col = convertLower.new(c)&lt;br /&gt;
 		converter = TextOperations.new(cou, col) # Client calls the invoker and gives the commands to execute&lt;br /&gt;
 		converter.convToLow()&lt;br /&gt;
 		converter.convToUp()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python Example ====&lt;br /&gt;
This contains the '''Command class''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create derived classes that inherit from the Command class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Command(object):&lt;br /&gt;
 	def execute(self):&lt;br /&gt;
 		pass&lt;br /&gt;
&lt;br /&gt;
 class convertLower(Command):&lt;br /&gt;
 	def __init__(self, conv):&lt;br /&gt;
 		self._convert = conv&lt;br /&gt;
 &lt;br /&gt;
 	def execute(self):&lt;br /&gt;
 		self._convert.toLower()&lt;br /&gt;
 class convertUpper(Command):&lt;br /&gt;
 	def __init__(self, conv):&lt;br /&gt;
 		self._convert = conv&lt;br /&gt;
 &lt;br /&gt;
 	def execute(self):&lt;br /&gt;
 		self._convert.toUpper()&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Convert(object):&lt;br /&gt;
 	def __init__(self):&lt;br /&gt;
 		pass&lt;br /&gt;
 	def toUpper(self):&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Turning all lower case elements to upper case&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 	def toLower(self):&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Converting all upper case elements to lower case&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''invoker class''' which contains the method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
 class TextOperations(object):&lt;br /&gt;
 	def __init__(self, toup, todwn):&lt;br /&gt;
 		self._convertUp = toup&lt;br /&gt;
 		self._convertLow = todwn&lt;br /&gt;
 &lt;br /&gt;
 	def convToUp(self):&lt;br /&gt;
 		self._convertUp.execute()&lt;br /&gt;
 &lt;br /&gt;
 	def convToLow(self):&lt;br /&gt;
 		self._convertLow.execute()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Menu(object):&lt;br /&gt;
 	def Main(self, args):&lt;br /&gt;
 		c = Convert()&lt;br /&gt;
 		cou = convertUpper(c)&lt;br /&gt;
 		col = convertLower(c)&lt;br /&gt;
 		converter = TextOperations(cou, col) # Client calls the invoker and gives the commands to execute&lt;br /&gt;
 		converter.convToLow()&lt;br /&gt;
 		converter.convToUp()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static vs Dynamic implementations ===&lt;br /&gt;
In case of the implementations ruby has better implementation of the command patterns than the languages like Java. Some of the advantages of Ruby over Java can be given as follows.&lt;br /&gt;
* To implement the command pattern in static languages like Java, we have to define a common interface which has to be extended by all the other classes. In case of ruby we can use procs which makes it easier to implement.&lt;br /&gt;
* Ruby implements something called mixins in order to implement the command pattern which is efficient compared to Java.&lt;br /&gt;
* The lines of code for static language like Java is more than that taken by the dynamic language like Ruby. This is more because of the proc objects that are present in ruby which are concisely defined than that present in Java.&lt;br /&gt;
* Since Ruby is a dynamic language, one can add the commands to the command array during runtime. Java is a static language and hence does not support this feature.&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
Hence it can be summarized that the dynamically typed languages keep the code straight and narrow as it does not need to depend on static type-checking. Also due to the flexibility of the dynamic languages, writing code is significantly easier.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Software_design_pattern Software Design Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Mediator_pattern Mediator Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Observer_pattern Observer Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Composite_pattern Composite Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Memento_pattern Memento Pattern]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References  ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.codeproject.com/Articles/15207/Design-Patterns-Command-Pattern Design Pattern: Command Pattern] at codeproject.com&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-command Command Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternCommand.aspx Command Pattern in C#] at dofactory.com&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
&lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w52_an&amp;diff=70983</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w52 an</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w52_an&amp;diff=70983"/>
		<updated>2012-11-20T01:03:48Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Command Pattern ''' ==&lt;br /&gt;
&lt;br /&gt;
Command Pattern is a [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) design pattern] in [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] in which an object is used to represent and [http://en.wikipedia.org/wiki/Encapsulation_(computer_science)#Encapsulation encapsulate] all the information needed to call a method at a later time. This information comprises of, the method name, the object that is the owner of the method and values for the method parameters. It encapsulates a request as an object and gives it a known public interface. It ensures that every object receives its own commands and provides a [http://en.wikipedia.org/wiki/Decoupling#Software_Development decoupling] between sender and receiver. In this case a sender is an object that invokes an operation, and a receiver is an object that receives the request and acts on it.&lt;br /&gt;
&lt;br /&gt;
There are three main components of a Command pattern: the ''Invoker'', the ''Command'', and the ''Receiver''. The invoker component acts as a link between the commands and the receiver, and houses the receiver and the individual commands as they are sent. The command is an object that encapsulates a request to the receiver. The receiver is the component that is acted upon by each request.&lt;br /&gt;
&lt;br /&gt;
The intent of using command objects is to easily construct the general components that need to sequence, delegate or execute method calls at a time of their choosing without the need to know the owner of the method or the method parameters. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
Developers might use a switch statement with a case for each command. Usage of Switch statements during coding is a sign of bad design during the design phase of an object-oriented project. Commands represent an object-oriented way to support transactions&amp;lt;ref&amp;gt;[http://www.oodesign.com/command-pattern.html Oodesign. (2005-2006)- command-pattern - http://www.oodesign.com/command-pattern.html]&amp;lt;/ref&amp;gt; and can be used to solve this design problem.&lt;br /&gt;
&lt;br /&gt;
== Why and When do we use a Command Pattern? ==&lt;br /&gt;
Command Pattern comes into picture when there is a need  to store objects behaviour as a command and its state. The Command pattern encapsulates commands (method calls) in objects allowing us to issue requests without knowing the requested operation or the requesting object. Command pattern provides the options to queue commands, undo/redo actions and other manipulations.&lt;br /&gt;
&lt;br /&gt;
There are several benefits&amp;lt;ref&amp;gt;[http://www.javaworld.com/javaworld/jw-06-2002/jw-0628-designpatterns.html Javaworld - Command Design Pattern  - http://www.javaworld.com/javaworld/jw-06-2002/jw-0628-designpatterns.html]&amp;lt;/ref&amp;gt; of using the Command pattern:&lt;br /&gt;
&lt;br /&gt;
* It provides encapsulation of application logic so that it can be executed at a different point of time.&lt;br /&gt;
&lt;br /&gt;
* It allows to execute the application in separate contexts, such as in a different thread or using a different state by separating the application logic and context.&lt;br /&gt;
&lt;br /&gt;
* The separation between application logic and context allows to easier exchange the application logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command Patterns can be used for the following:&lt;br /&gt;
&lt;br /&gt;
'''Undo and redo actions'''&lt;br /&gt;
&lt;br /&gt;
There is support for undo and redo of actions in certain implementations of the Command design pattern. In order to do that, a mechanism to obtain past states of the Receiver object is needed; there are two options to achieve this:&lt;br /&gt;
* Before running each command a snapshot of the receiver state is stored in memory. This does not require much programming effort but can not be always applied. For example doing this in an image processing application would require storing images in memory after each step, which is practically impossible. &lt;br /&gt;
* Instead of storing receiver objects states, the set of performed operations are stored in memory. In this case the command and receiver classes should implement the inverse algorithms to undo each action. This will require additional programming effort, but less memory will be required. Sometimes for undo/redo actions the command should store more information about the state of the receiver objects. A good idea in such cases is to use the [http://en.wikipedia.org/wiki/Memento_pattern Memento Pattern].&lt;br /&gt;
&lt;br /&gt;
'''Asynchronous Method Invocation'''&lt;br /&gt;
&lt;br /&gt;
Another usage for the command design pattern is to run commands asynchronous in background of an application. In this case the invoker is running in the main thread and sends the requests to the receiver which is running in a separate thread. The invoker will keep a queue of commands to be run and will send them to the receiver while it finishes running them.&lt;br /&gt;
&lt;br /&gt;
Instead of using one thread in which the receiver is running more threads can be created for this. But for performance issues (thread creation is consuming) the number of threads should be limited. In this case the invoker will use a pool of receiver threads to run command asynchronously.&lt;br /&gt;
&lt;br /&gt;
'''Adding new commands'''&lt;br /&gt;
&lt;br /&gt;
The command object decouples the object that invokes the action from the object that performs the action. There are implementations of the pattern in which the invoker instantiates the concrete command objects. In this case if we need to add a new command type we need to change the invoker as well. And this would violate the Open Close Principle (OCP). In order to have the ability to add new commands with minimum of effort we have to make sure that the invoker is aware only about the abstract command class or interface.&lt;br /&gt;
&lt;br /&gt;
'''Using composite commands'''&lt;br /&gt;
&lt;br /&gt;
When adding new commands to the application we can use the [http://en.wikipedia.org/wiki/Composite_pattern composite pattern] to group existing commands in another new command. This way, macros can be created from existing commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
There are many applications&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Command_pattern Wikipedia. (2010, October) Wikipedia - Command_Pattern - http://en.wikipedia.org/wiki/Command_pattern]&amp;lt;/ref&amp;gt; that make use of command pattern.Command objects are useful for implementing:&lt;br /&gt;
&lt;br /&gt;
; In Networking : In case of computer games,player actions can to send whole command objects across the network to be executed on the other machines.&lt;br /&gt;
; In parallel processing : In parallel processing, tasks may be referred as the commands to a shared resource. These tasks will be executed by many threads in parallel.This can be considered as a Client/Server model.&lt;br /&gt;
; Graphical User Interface buttons: An [http://docs.oracle.com/javase/7/docs/api/javax/swing/Action.html Action] is a command object in case of [http://en.wikipedia.org/wiki/Swing_(Java) Swings]. A submit button, menu button or checkbox button component may be completely initialized using only the &amp;lt;code&amp;gt;Action&amp;lt;/code&amp;gt; object. In a given scenario,an Action may have an icon bound to it ,mouse click,a keyboard shortcut in addition to the ability to perform the desired command.&lt;br /&gt;
; Multi-level [http://en.wikipedia.org/wiki/Undo undo] : The program can keep a stack of the most recently executed commands if all user actions in a program are implemented as command objects. The program simply pops the most recent command object and executes its &amp;lt;tt&amp;gt;undo()&amp;lt;/tt&amp;gt; method when the user wants to undo a command.&lt;br /&gt;
; [http://en.wikipedia.org/wiki/Database_transaction Transactional behavior of Databases] : A database engine or software installer may keep a list of operations that have been or will be performed similar to undo.All others can be reverted or discarded if one of them fail. For instance, if two database tables that refer to each other must be updated, and the second update fails, the transaction can be rolled back, so that the first table does not now contain an invalid reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Components of a command pattern ==&lt;br /&gt;
The various components&amp;lt;ref&amp;gt;Freeman,E., and Robson,E.,and Bates,B.,and Sierra,K. 2004. Head First Design Patterns&amp;lt;/ref&amp;gt; of a command pattern are given as follows:&lt;br /&gt;
&lt;br /&gt;
'''Client:''' Invokes a particular module using a command and passes a request which gets propagated as a command.&lt;br /&gt;
&lt;br /&gt;
'''Command:''' It is an object that encapsulates a request to the receiver. Command request maps to particular modules. According to the command, a module is invoked.&lt;br /&gt;
&lt;br /&gt;
'''Receiver:''' It is the component that is acted upon by each request. It knows how to perform the operations associated with carrying out a certain request.&lt;br /&gt;
&lt;br /&gt;
'''Invoker:''' It is the class that is invoked by the client. It takes in the request and calls the receiver by passing the command to it and asks it to carry out the request.&lt;br /&gt;
&lt;br /&gt;
'''Concrete Command:''' It defines a link between the receiver and the action. It basically implements the execute method and invokes the corresponding operations on the receiver.&lt;br /&gt;
&lt;br /&gt;
Throughout this page, we will discuss the example of an operation of converting a string into either upper case or lower case. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:WIKI.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The components corresponding to the example are given in the figure above. From the figure we can identify the components as follows: &lt;br /&gt;
&lt;br /&gt;
'''Client:''' Menu Class is used to set the ConcreteCommand and then sets the convert class &lt;br /&gt;
&lt;br /&gt;
'''Command:''' Command Class in this case is declaring the interface which is used to execute the operation.&lt;br /&gt;
&lt;br /&gt;
'''Receiver:''' Convert Class is the one which knows how to perform the operations.&lt;br /&gt;
&lt;br /&gt;
'''Invoker:'''  TextOperation Class asks the command to carry out the action which in this case is to either convert toUpper or toLower.&lt;br /&gt;
&lt;br /&gt;
'''ConcreteCommand:''' ConvertUpper, ConvertLower classes are the ones that implement the execute command.&lt;br /&gt;
&lt;br /&gt;
==Terminology==&lt;br /&gt;
&lt;br /&gt;
The terminology used to describe command pattern implementations can be confusing sometimes.&lt;br /&gt;
* '''Command Object, Routed Command Object and Action Object''': In this, we can refer a singleton object which knows about mouse click , button images, shortcut keys and so on related to the command. A invoker object calls the Action object's performAction method.When the availability of a command/action has changed, the Command/Action object notifies the appropriate source/invoker objects.When a command/action cannot be executed/performed, this allows buttons and menu items to become inactive.&lt;br /&gt;
* '''Client, Source and Invoker''': It refers to a button, toolbar button, or radio button clicked, or the shortcut key pressed by the user.&lt;br /&gt;
* '''Receiver, Target Object''': This is the object that is about will be copied, pasted or perform some other function . The receiver object owns the method that is called by the command's ''execute'' method. The receiver is  also the target object. For instance, if the receiver object is a ''cursor'' and the method is called ''moveDown'', then one would expect that the cursor is the target of the moveDown action.&lt;br /&gt;
* '''Handler, method, ''': This is the actual code that does the copying, pasting  etc.There are many variants of the handler. This is the handler code of the action object in some implementations. In other implementations the code is part of the Receiver/Target Object.Finally in some other implementations the handler code is kept separate from the other objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Check list for Command Pattern Implementation ==&lt;br /&gt;
&lt;br /&gt;
* Define a Command interface with a method signature like &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Create one or more derived classes that encapsulate some subset of the following: a “receiver” object, the method to invoke, the arguments to pass.&lt;br /&gt;
* Instantiate a Command object for each deferred execution request.&lt;br /&gt;
* Pass the Command object from the creator (aka sender) to the invoker (aka receiver).&lt;br /&gt;
* The invoker decides when to &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Rules of thumb&amp;lt;ref&amp;gt;Erich,G., and Richard,H.,and Ralph,J.,and John,M.V. 1997. Design Patterns: Elements of Reusable Object-Oriented Software&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], Command, [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], and [http://en.wikipedia.org/wiki/Observer_pattern Observer], address how you can decouple senders and receivers, but with different trade-offs. *Command normally specifies a sender-receiver connection with a subclass.&lt;br /&gt;
*Chain of Responsibility can use Command to represent requests as objects.&lt;br /&gt;
*Command and Memento act as magic tokens to be passed around and invoked at a later time. In Command, the token represents a request; in *Memento, it represents the internal state of an object at a particular time. Polymorphism is important to Command, but not to Memento because its interface is so narrow that a memento can only be passed as a value.&lt;br /&gt;
*Command can use Memento to maintain the state required for an undo operation.&lt;br /&gt;
*MacroCommands can be implemented with Composite.&lt;br /&gt;
*A Command that must be copied before being placed on a history list acts as a Prototype.&lt;br /&gt;
*Two important aspects of the Command pattern: interface separation (the invoker is isolated from the receiver), time separation (stores a ready-to-go processing request that’s to be stated later).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example of Command pattern ==&lt;br /&gt;
&lt;br /&gt;
Consider the case of converting a string to upper and lower case.The Client is the Menu where we see the options. The menu sends the request to the receiver(convert class) through the Invoker(TextOperations class). The textOperation encapsulates the command and then forwards it, creating the ConcreteCommand object which is the command itself. The Receiver will be the Convert class that, after completing all the commands that were sent to it before the command in question(to Upper case or to lower case ), starts to work on it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation in static and dynamic languages ==&lt;br /&gt;
&lt;br /&gt;
=== Implementation in Static languages ===&lt;br /&gt;
We initially define a Command interface with a method named execute() and then we create command classes that implement this interface. The execute() method of each object will contain the logic specific to the action you are encapsulating. &lt;br /&gt;
(For instance, you might create a convertUpper and a converLower command in a text editor application.)&lt;br /&gt;
&lt;br /&gt;
In case of the static implementation, code snippets to implement the command pattern in languages like Java and C# are given as follows:&lt;br /&gt;
&lt;br /&gt;
==== Java Example ====&lt;br /&gt;
This contains the '''Command interface''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create command classes that implement this interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public interface Command{&lt;br /&gt;
     void execute();&lt;br /&gt;
 }&lt;br /&gt;
 //A command to convert to lower case.&lt;br /&gt;
 public class convertLower implements Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertLower(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toLower();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
//A command to convert to upper case&lt;br /&gt;
 public class convertUpper implements Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertUpper(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toUpper();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''invoker class''' which contains the method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class TextOperations{&lt;br /&gt;
    private ArrayList&amp;lt;Command&amp;gt; Command_List= new ArrayList&amp;lt;Command&amp;gt;;&lt;br /&gt;
        private TextOperations(){&lt;br /&gt;
        }&lt;br /&gt;
        public void commandExecute(Command cmd){&lt;br /&gt;
        this.Command_List.add(cmd); // optional &lt;br /&gt;
         cmd.execute();     &lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class Convert{&lt;br /&gt;
    public Convert(){&lt;br /&gt;
    }&lt;br /&gt;
    public final void toUpper(){&lt;br /&gt;
        System.out.print(&amp;quot;Turning all lower case elements to upper case&amp;quot;);//The actual action that is being performed.&lt;br /&gt;
    }&lt;br /&gt;
    public final void toLower(){&lt;br /&gt;
        System.out.print(&amp;quot;Converting all upper case elements to lower case&amp;quot;);//The actual action that is being performed.&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class Menu{&lt;br /&gt;
   public static void main(String[] args){&lt;br /&gt;
      Convert c = new Convert();&lt;br /&gt;
      Command conToUpper = new convertUpper(c);&lt;br /&gt;
      Command conToLower = new convertLower(c);&lt;br /&gt;
 &lt;br /&gt;
      TextOperations converter = new TextOperations(); &lt;br /&gt;
         if (args[0].equalsIgnoreCase(&amp;quot;ToUpper&amp;quot;)) {&lt;br /&gt;
            converter.commandExecute(conToUpper);&lt;br /&gt;
            System.exit(0);&lt;br /&gt;
         }&lt;br /&gt;
         if (args[0].equalsIgnoreCase(&amp;quot;ToLower&amp;quot;)) {&lt;br /&gt;
            converter.commandExecute(conToLower);&lt;br /&gt;
            System.exit(0);&lt;br /&gt;
         }       &lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== C# Example ====&lt;br /&gt;
This contains the '''Command interface''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create command classes that implement this interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public interface Command&lt;br /&gt;
 {&lt;br /&gt;
     void execute(); //The execute method that is going to call the action&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 //A command to convert to lower case.&lt;br /&gt;
 public class convertLower : Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertLower(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toLower();&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 //A command to convert to upper case&lt;br /&gt;
 public class convertUpper : Command{&lt;br /&gt;
    private Convert convert;&lt;br /&gt;
    private convertUpper(Convert conv){&lt;br /&gt;
        this.convert = conv;&lt;br /&gt;
    }&lt;br /&gt;
    public void execute(){&lt;br /&gt;
        convert.toUpper();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
This is the '''invoker class''' which contains method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as the parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class TextOperations{&lt;br /&gt;
    private ArrayList&amp;lt;Command&amp;gt; _command_List= new ArrayList&amp;lt;Command&amp;gt;;&lt;br /&gt;
        private TextOperations(){&lt;br /&gt;
        }&lt;br /&gt;
        public void commandExecute(Command cmd){&lt;br /&gt;
        _commands.add(cmd); // optional &lt;br /&gt;
         cmd.execute();     &lt;br /&gt;
        }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
 public class Convert{&lt;br /&gt;
    public Convert(){&lt;br /&gt;
    }&lt;br /&gt;
    public final void toUpper(){&lt;br /&gt;
        Console.WriteLine(&amp;quot;Turning all lower case elements to upper case&amp;quot;);// These are the actual actions that are performed&lt;br /&gt;
    }&lt;br /&gt;
    public final void toLower(){&lt;br /&gt;
        Console.WriteLine(&amp;quot;Converting all upper case elements to lower case&amp;quot;); //These is the actual action that is performed&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 public class Menu&lt;br /&gt;
 {&lt;br /&gt;
    Static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        Convert c = new Convert();&lt;br /&gt;
        Command conToUpper = new convertUpper(c);&lt;br /&gt;
        Command conToLower = new convertLower(c);&lt;br /&gt;
        TextOperations converter = new TextOperations(); /*Client calls the invoker and gives the commands to execute*/&lt;br /&gt;
                if (args[0].ToUpper().Equals(&amp;quot;toUpper&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    converter.commandExecute(conToUpper);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
                if (args[0].ToUpper().Equals(&amp;quot;tolower&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    converter.commandExecute(conToLower);&lt;br /&gt;
                    return;&lt;br /&gt;
                }               &lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Implementation in Dynamic Languages ===&lt;br /&gt;
&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic languages] we will have a controller class that constructs each of the Command objects.Each of these command objects is passed to an invoker class. The invoker class calls the execute() method of a Command object at the appropriate time. &lt;br /&gt;
(For instance this may happen when a user selects a menu item or presses a button)&lt;br /&gt;
&lt;br /&gt;
In case of the dynamic languages, the code snippets to implement command pattern for ruby and python are given as follows.&lt;br /&gt;
&lt;br /&gt;
==== Ruby Example ====&lt;br /&gt;
This contains the '''Command class''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create derived classes that inherit from the Command class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Command&lt;br /&gt;
 	def execute()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
 class convertLower &amp;lt; Command&lt;br /&gt;
 	def initialize(conv)&lt;br /&gt;
 		self.@convert = conv&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def execute()&lt;br /&gt;
 		@convert.toLower()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
 class convertUpper &amp;lt; Command&lt;br /&gt;
 	def initialize(conv)&lt;br /&gt;
 		self.@convert = conv&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def execute()&lt;br /&gt;
 		@convert.toUpper()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Convert&lt;br /&gt;
 	def initialize()&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def toUpper()&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Turning all lower case elements to upper case&amp;quot;)&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def toLower()&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Converting all upper case elements to lower case&amp;quot;)&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''invoker class''' which contains the method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class TextOperations&lt;br /&gt;
 	def initialize(toup, todwn)&lt;br /&gt;
 		self.@convertUp = toup&lt;br /&gt;
 		self.@convertLow = todwn&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def convToUp()&lt;br /&gt;
 		@convertUp.execute()&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
 	def convToLow()&lt;br /&gt;
 		@convertLow.execute()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Menu&lt;br /&gt;
 	def Main(args)&lt;br /&gt;
 		c = Convert.new()&lt;br /&gt;
 		cou = convertUpper.new(c)&lt;br /&gt;
 		col = convertLower.new(c)&lt;br /&gt;
 		converter = TextOperations.new(cou, col) # Client calls the invoker and gives the commands to execute&lt;br /&gt;
 		converter.convToLow()&lt;br /&gt;
 		converter.convToUp()&lt;br /&gt;
 	end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python Example ====&lt;br /&gt;
This contains the '''Command class''' with a method named &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt; and then we create derived classes that inherit from the Command class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Command(object):&lt;br /&gt;
 	def execute(self):&lt;br /&gt;
 		pass&lt;br /&gt;
&lt;br /&gt;
 class convertLower(Command):&lt;br /&gt;
 	def __init__(self, conv):&lt;br /&gt;
 		self._convert = conv&lt;br /&gt;
 &lt;br /&gt;
 	def execute(self):&lt;br /&gt;
 		self._convert.toLower()&lt;br /&gt;
 class convertUpper(Command):&lt;br /&gt;
 	def __init__(self, conv):&lt;br /&gt;
 		self._convert = conv&lt;br /&gt;
 &lt;br /&gt;
 	def execute(self):&lt;br /&gt;
 		self._convert.toUpper()&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''receiver class''' which knows how to perform the operations. Here receiver class has the implementation of &amp;lt;code&amp;gt;toUpper()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;toLower()&amp;lt;/code&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Convert(object):&lt;br /&gt;
 	def __init__(self):&lt;br /&gt;
 		pass&lt;br /&gt;
 	def toUpper(self):&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Turning all lower case elements to upper case&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 	def toLower(self):&lt;br /&gt;
 		Console.WriteLine(&amp;quot;Converting all upper case elements to lower case&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''invoker class''' which contains the method &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; that takes Command object as parameter and asks the Command to carry out the action by executing its &amp;lt;code&amp;gt;execute()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
 class TextOperations(object):&lt;br /&gt;
 	def __init__(self, toup, todwn):&lt;br /&gt;
 		self._convertUp = toup&lt;br /&gt;
 		self._convertLow = todwn&lt;br /&gt;
 &lt;br /&gt;
 	def convToUp(self):&lt;br /&gt;
 		self._convertUp.execute()&lt;br /&gt;
 &lt;br /&gt;
 	def convToLow(self):&lt;br /&gt;
 		self._convertLow.execute()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is the '''client class''' which creates object of class Convert and calls the &amp;lt;code&amp;gt;commandExecute()&amp;lt;/code&amp;gt; method based on the argument passed in command line &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 class Menu(object):&lt;br /&gt;
 	def Main(self, args):&lt;br /&gt;
 		c = Convert()&lt;br /&gt;
 		cou = convertUpper(c)&lt;br /&gt;
 		col = convertLower(c)&lt;br /&gt;
 		converter = TextOperations(cou, col) # Client calls the invoker and gives the commands to execute&lt;br /&gt;
 		converter.convToLow()&lt;br /&gt;
 		converter.convToUp()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Static vs Dynamic implementations ===&lt;br /&gt;
In case of the implementations ruby has better implementation of the command patterns than the languages like Java. Some of the advantages of Ruby over Java can be given as follows.&lt;br /&gt;
* To implement the command pattern in static languages like Java, we have to define a common interface which has to be extended by all the other classes. In case of ruby we can use procs which makes it easier to implement.&lt;br /&gt;
* Ruby implements something called mixins in order to implement the command pattern which is efficient compared to Java.&lt;br /&gt;
* The lines of code for static language like Java is more than that taken by the dynamic language like Ruby. This is more because of the proc objects that are present in ruby which are concisely defined than that present in Java.&lt;br /&gt;
* Since Ruby is a dynamic language, one can add the commands to the command array during runtime. Java is a static language and hence does not support this feature.&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
Hence it can be summarized that the dynamically typed languages keep the code straight and narrow as it does not need to depend on static type-checking. Also due to the flexibility of the dynamic languages, writing code is significantly easier.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Software_design_pattern Software Design Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Mediator_pattern Mediator Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Observer_pattern Observer Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Composite_pattern Composite Pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Memento_pattern Memento Pattern]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References  ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.dofactory.com/topic/1675/facade-with-factory-pattern.aspx Facade with Factory pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternCommand.aspx Command Pattern in C#] at dofactory.com&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
&lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70981</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70981"/>
		<updated>2012-11-20T01:02:32Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional Reading ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.codeproject.com/Articles/15207/Design-Patterns-Command-Pattern Design Pattern: Command Pattern] at codeproject.com&lt;br /&gt;
* [http://java.dzone.com/articles/design-patterns-command Command Pattern in Java] at java.dzone.com&lt;br /&gt;
* [http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html Basics of Command Pattern]&lt;br /&gt;
* [http://www.dofactory.com/Patterns/PatternCommand.aspx Command Pattern in C#] at dofactory.com&lt;br /&gt;
&lt;br /&gt;
* [http://sourcemaking.com/design_patterns/command Behavorial Design Pattern - Command Pattern] at sourcemaking.com&lt;br /&gt;
&lt;br /&gt;
* [http://perfectjpattern.sourceforge.net/dp-command.html GoF Command Pattern]&lt;br /&gt;
&lt;br /&gt;
* McDonald,J. 2008. Design Patterns&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70979</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70979"/>
		<updated>2012-11-20T01:02:17Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70978</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70978"/>
		<updated>2012-11-20T01:00:51Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Non-Software examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples&amp;lt;ref&amp;gt;[http://aspalliance.com/970_Facade_Design_Pattern.2 ASPAlliance - Facade Design Pattern  - http://aspalliance.com/970_Facade_Design_Pattern.2]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70973</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70973"/>
		<updated>2012-11-20T00:54:57Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70971</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70971"/>
		<updated>2012-11-20T00:54:18Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities between Facade and Abstract Factory patterns ==&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Facade is a structural design pattern whereas Abstract Factory pattern is a creational design pattern.&lt;br /&gt;
&amp;lt;li&amp;gt;Both are similar in a way that both provide an interface. Abstract Factory , provides kind of a Facade for creating products that belongs to its own factories.&lt;br /&gt;
&amp;lt;li&amp;gt;With the Abstract Factory Pattern we just provide a common factory builder for many different builders for the same thing. This can be used whenever we need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are we going to build or which factory are we going to use. The Facade pattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70964</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70964"/>
		<updated>2012-11-20T00:40:11Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
Thus we see that both patterns achieve quite different goals. The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. On the other hand Abstarct factory pattern is used when you want to hide the details on constructing instances. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70957</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70957"/>
		<updated>2012-11-20T00:36:36Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Considering the example for the Facade pattern, Client requires access to Employee objects, but in order to get that, it first need to contact the Database and retrieve the Company objects. It then retrieves Division objects from them and finally gains access to Employee objects. So, we see that It uses four classes and has to deal with complex details of the sub system. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70951</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70951"/>
		<updated>2012-11-20T00:32:12Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences and similarities ==&lt;br /&gt;
* In both the Facade and Adapter pattern we have pre-existing classes.&lt;br /&gt;
* In the Facade, however, we do not have an interface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
* We are not interested in polymorphic behavior in the Facade, while in the Adapter, We probably am.(There are times when we just need to design to a particular API and therefore must use an Adapter)&lt;br /&gt;
* In the case of the Facade pattern, the motivation is to simplify the interface. With the Adapter, while simpler is better,We are trying to design to an existing interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line is a Facade simplifies an interface while an Adapter converts the interface into a pre-existing interface.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt;=&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70945</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70945"/>
		<updated>2012-11-20T00:30:12Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70944</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70944"/>
		<updated>2012-11-20T00:29:55Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|left|Without a Facade, the client has to deal with the intricacies of the sub system.]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the complexities of sub system are unified into a single interface making it readily usable for the client.]]&lt;br /&gt;
&lt;br /&gt;
Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
Colleagues (or peers) are not coupled to one another. Each talks to the Mediator, which in turn knows and conducts the orchestration of the others. The “many to many” mapping between colleagues that would otherwise exist, has been “promoted to full object status”. This new abstraction provides a locus of indirection where additional leverage can be hosted.&lt;br /&gt;
&lt;br /&gt;
Mediator is similar to Facade in that it abstracts functionality of existing classes. Mediator abstracts/centralizes arbitrary communication between colleague objects, it routinely “adds value”, and it is known/referenced by the colleague objects (i.e. it defines a multidirectional protocol). In contrast, Facade defines a simpler interface to a subsystem, it doesn’t add new functionality, and it is not known by the subsystem classes (i.e. it defines a unidirectional protocol where it makes requests of the subsystem classes but not vice versa).&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70939</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70939"/>
		<updated>2012-11-20T00:27:25Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* Design an intermediary to decouple many peers.&lt;br /&gt;
* Promote the many-to-many relationships between interacting peers to “full object status”.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
On similar lines, assume that the implementation and structure of BasketItem in Facade example needs to be changed. To handle such scenario, a new adapter class BasketItemAdapter is defined. It implements all the methods of the BasketItem and in each method makes necessary changes to the arguments and passes it to the new implementation as shown below.&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class BasketItemAdapter {&lt;br /&gt;
  BasketItem newImplementation = new BasketItem();&lt;br /&gt;
  void calculateCost(...) {&lt;br /&gt;
    //make necessary modification&lt;br /&gt;
    newImplementation.calculateCost(...);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade]]&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade]]&lt;br /&gt;
&lt;br /&gt;
Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes. With Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
In Unix, permission to access system resources is managed at three levels of granularity: world, group, and owner. A group is a collection of users intended to model some functional affiliation. Each user on the system can be a member of one or more groups, and each group can have zero or more users assigned to it. Next figure shows three users that are assigned to all three groups. If we were to model this in software, we could decide to have User objects coupled to Group objects, and Group objects coupled to User objects. Then when changes occur, both classes and all their instances would be affected. An alternate approach would be to introduce “an additional level of indirection” - take the mapping of users to groups and groups to users, and make it an abstraction unto itself. This offers several advantages: Users and Groups are decoupled from one another, many mappings can easily be maintained and manipulated simultaneously, and the mapping abstraction can be extended in the future by defining derived classes.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Partitioning a system into many objects generally enhances reusability, but proliferating interconnections between those objects tend to reduce it again. The mediator object: encapsulates all interconnections, acts as the hub of communication, is responsible for controlling and coordinating the interactions of its clients, and promotes loose coupling by keeping objects from referring to each other explicitly.&lt;br /&gt;
&lt;br /&gt;
[[File:Mediator__1.gif]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70923</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70923"/>
		<updated>2012-11-20T00:11:49Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Abstract factory pattern provides a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|center|]]&lt;br /&gt;
Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|center|]]&lt;br /&gt;
With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70920</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70920"/>
		<updated>2012-11-20T00:09:22Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|center|]]&lt;br /&gt;
Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|center|]]&lt;br /&gt;
With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70919</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70919"/>
		<updated>2012-11-20T00:07:14Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|]]&lt;br /&gt;
Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|]]&lt;br /&gt;
With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70918</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70918"/>
		<updated>2012-11-20T00:05:29Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Software examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70916</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70916"/>
		<updated>2012-11-20T00:04:35Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Example ==&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Facade Pattern Example ==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70914</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70914"/>
		<updated>2012-11-20T00:03:43Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Abstract.JPG|600px|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70912</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70912"/>
		<updated>2012-11-20T00:02:48Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Abstract.JPG|center]]&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70910</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70910"/>
		<updated>2012-11-20T00:01:13Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Abstract Factory Pattern and Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide a unified interface to a set of interfaces in a subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
* Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
* Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
* A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
* The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Non-Software examples==&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
&lt;br /&gt;
==Software examples==&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Adapter Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class. An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed. Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards. It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Shape {&lt;br /&gt;
  void draw(...);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyLine {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class LegacyRectangle {&lt;br /&gt;
  void draw(..) { }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Line implements Shape {&lt;br /&gt;
  adapter = new LegacyLine();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  adapter = new LegacyRectangle();&lt;br /&gt;
  void draw(...) {adapter.draw(...)}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Facade pattern, the method placeOrder() uses the methods exposed by many other classes such as Order, OrderLine, Address etc to provide a high level view for the callers. The callers need not worry about the complexities in handling the sub-system. The users of the Class OrderFacade just invoke the method placeOrder() with the necessary arguments and rest of the process is taken care by placeOrder(). As can be seen in this case, a new method (placeOrder) was defined which has the logic and the necessary steps to handle all the sub-systems to create an order, create an id for the order, create a dispatch address etc.&lt;br /&gt;
&lt;br /&gt;
In the example provided for the Adapter pattern, no new methods are defined. The existing method draw of LegacyRectangle is wrapped in a adapter class Rectangle. The methods in adapter classes does the necessary manipulations to the arguments and then passes to the original classes.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class RectangularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
     //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class CircularShipment implements Cost {&lt;br /&gt;
   double calculateCost(CustomerId, OrderId, Address) {&lt;br /&gt;
    //based on dimensions calculate packaging cost&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The AbstractFactory defines the interface that all of the concrete factories will need to implement in order to product Products. ConcreteFactoryA and ConcreteFactoryB have both implemented this interface here, creating two seperate families of product. Meanwhile, AbstractProductA and AbstractProductB are interfaces for the different types of product. Each factory will create one of each of these AbstractProducts. &lt;br /&gt;
&lt;br /&gt;
The Client deals with AbstractFactory, AbstractProductA and AbstractProductB. It doesn't know anything about the implementations. The actual implementation of AbstractFactory that the Client uses is determined at runtime.&lt;br /&gt;
&lt;br /&gt;
As you can see, one of the main benefits of this pattern is that the client is totally decoupled from the concrete products. Also, new product families can be easily added into the system, by just adding in a new type of ConcreteFactory that implements AbstractFactory, and creating the specific Product implementations.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Mediator Pattern and Facade Pattern&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Differences n similarities between Adapter and Facade&amp;lt;/b&amp;gt;=&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Abstract.JPG&amp;diff=70909</id>
		<title>File:Abstract.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Abstract.JPG&amp;diff=70909"/>
		<updated>2012-11-20T00:00:51Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70487</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70487"/>
		<updated>2012-11-19T03:15:17Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* C# Example of above VB code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== C# Example ==&lt;br /&gt;
&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace Yanesh.DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70486</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70486"/>
		<updated>2012-11-19T03:15:02Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== C# Example of above VB code ==&lt;br /&gt;
&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace Yanesh.DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70485</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70485"/>
		<updated>2012-11-19T03:14:14Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace Yanesh.DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70484</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70484"/>
		<updated>2012-11-19T03:13:49Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 using System;&lt;br /&gt;
 using System.Collections.Generic;&amp;lt;br&amp;gt;&lt;br /&gt;
 namespace Yanesh.DesignPatterns.Facade&lt;br /&gt;
 {&lt;br /&gt;
    public class OrderFacade&lt;br /&gt;
    {&lt;br /&gt;
        //Places an Order and Returns an Order ID&lt;br /&gt;
        public int placeOrder(int CustomerID, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
            Order anOrder = new Order();&lt;br /&gt;
            OrderLine anOrderLine = new OrderLine();&lt;br /&gt;
            Address DespatchAddress = Address.getCustomerDespatchAddress(CustomerID);&lt;br /&gt;
            int OrderId = anOrder.requestOrderID();&lt;br /&gt;
&lt;br /&gt;
            anOrder.createOrder(OrderId, DespatchAddress);&lt;br /&gt;
            anOrderLine.addOrderLinesToOrder(OrderId, Products);&lt;br /&gt;
&lt;br /&gt;
            return OrderId;&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //order class&lt;br /&gt;
    public class Order&lt;br /&gt;
    {&lt;br /&gt;
        public int requestOrderID()&lt;br /&gt;
        {&lt;br /&gt;
            //Creates and Returns a Unique Order ID&lt;br /&gt;
        }&amp;lt;br&amp;gt;&lt;br /&gt;
        public void createOrder(int OrderId, Address DespatchAddress)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    //OrderLine Class&lt;br /&gt;
    public class OrderLine&lt;br /&gt;
    {&lt;br /&gt;
        public void addOrderLinesToOrder(int OrderId, List&amp;lt;BasketItem&amp;gt; Products)&lt;br /&gt;
        {&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;br&amp;gt;    &lt;br /&gt;
    //Public Customer&lt;br /&gt;
    public class Address&lt;br /&gt;
    {&lt;br /&gt;
        public static Address getCustomerDespatchAddress(int CustomerID)&lt;br /&gt;
        {&lt;br /&gt;
            return new Address();&lt;br /&gt;
        }&lt;br /&gt;
        //Address properties&lt;br /&gt;
    }&amp;lt;br&amp;gt;&lt;br /&gt;
    public class BasketItem&lt;br /&gt;
    {&lt;br /&gt;
        //BasketItem Properties&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70481</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70481"/>
		<updated>2012-11-19T03:10:31Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 ' This code would be run at page code behind level&lt;br /&gt;
 Dim aPayment As IPayment&lt;br /&gt;
 Dim paymentType As String ' this value would be populated elsewhere&amp;lt;br&amp;gt;&lt;br /&gt;
 aPayment = PaymentFactory.getPayment(paymentType)&lt;br /&gt;
 aPayment.takePayment(10.5)&amp;lt;br&amp;gt;&lt;br /&gt;
 ' The payment interface&lt;br /&gt;
 Public Interface IPayment&lt;br /&gt;
    Sub takePayment(ByVal Amount As Double)&lt;br /&gt;
 End Interface&amp;lt;br&amp;gt;&lt;br /&gt;
 ' PayPal Payment class that implements the IPayment Interface&lt;br /&gt;
 Public Class PayPalPayment&lt;br /&gt;
    Implements IPayment     &lt;br /&gt;
    Public Sub takePayment(ByVal Amount As Double) Implements IPayment.takePayment&lt;br /&gt;
        ' Code to take payment via PayPal merchant&lt;br /&gt;
    End Sub&lt;br /&gt;
 End Class&amp;lt;br&amp;gt;&lt;br /&gt;
 ' Credit Card Payment class that implements the IPayment Interface&lt;br /&gt;
 Public Class CreditCardPayment&lt;br /&gt;
    Implements IPayment     &lt;br /&gt;
    Public Sub takePayment(ByVal Amount As Double) Implements IPayment.takePayment&lt;br /&gt;
       ' Code to take payment via a credit card&lt;br /&gt;
    End Sub&lt;br /&gt;
 End Class&amp;lt;br&amp;gt;&lt;br /&gt;
 ' Adapter Class to ensure third party code implements IPayment&lt;br /&gt;
 Public Class ThirdPartyPaymentAdapter&lt;br /&gt;
    Inherits ThirdPartyPayment&lt;br /&gt;
    Implements IPayment     &lt;br /&gt;
    Public Sub takePayment(ByVal Amount As Double) Implements IPayment.takePayment&lt;br /&gt;
       ' This methods calls the actual thrid party code.&lt;br /&gt;
       ' If we couldn't inherit we could instantiate the object here or in the &lt;br /&gt;
       ' constructor method.&lt;br /&gt;
       MyBase.makeTransasction(Amount, False)&lt;br /&gt;
    End Sub&lt;br /&gt;
 End Class&amp;lt;br&amp;gt;&lt;br /&gt;
 ' Third Party Payment Class&lt;br /&gt;
 Public Class ThirdPartyPayment    &lt;br /&gt;
   Public Sub makeTransasction(ByVal amount As Double, ByVal refund As Boolean)&lt;br /&gt;
      ' Third party code...&lt;br /&gt;
   End Sub&lt;br /&gt;
 End Class&amp;lt;br&amp;gt;&lt;br /&gt;
 ' Factory Class to return Concrete Payment object&lt;br /&gt;
 Public Class PaymentFactory    &lt;br /&gt;
   Public Shared Function getPayment(ByVal PaymentType As String) As IPayment&lt;br /&gt;
       Select Case PaymentType&lt;br /&gt;
           Case &amp;quot;CreditCard&amp;quot;&lt;br /&gt;
               Return New CreditCardPayment&lt;br /&gt;
           Case &amp;quot;PayPal&amp;quot;&lt;br /&gt;
               Return New PayPalPayment&lt;br /&gt;
           Case Else&lt;br /&gt;
               Return New ThirdPartyPaymentAdapter&lt;br /&gt;
       End Select&lt;br /&gt;
   End Function&lt;br /&gt;
 End Class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70473</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70473"/>
		<updated>2012-11-19T02:57:37Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG|300px|thumb|center|Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.]]&lt;br /&gt;
[[File:Facade-w.JPG|300px|thumb|center|With a Facade, the Client is shielded from most of the classes. It uses the Database Facade to retrieve Employee objects directly.]]&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70469</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70469"/>
		<updated>2012-11-19T02:52:28Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG]] &amp;lt;br&amp;gt;&lt;br /&gt;
Without a Facade, Client contacts the Database&amp;lt;br&amp;gt;&lt;br /&gt;
to retrieve Company objects. It then retrieves&amp;lt;br&amp;gt;&lt;br /&gt;
Division objects from them and finally gains access&amp;lt;br&amp;gt;&lt;br /&gt;
to Employee objects.It uses four classes.&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70467</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70467"/>
		<updated>2012-11-19T02:50:26Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG]] Without a Facade, Client contacts the Database to retrieve Company objects. It then retrieves Division objects from them and finally gains access to Employee objects.It uses four classes.&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70464</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70464"/>
		<updated>2012-11-19T02:48:54Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG]] Without a Facade, &lt;br /&gt;
Client contacts the &lt;br /&gt;
Database to retrieve &lt;br /&gt;
Company objects. It &lt;br /&gt;
then retrieves &lt;br /&gt;
Division objects from &lt;br /&gt;
them and finally &lt;br /&gt;
gains access to &lt;br /&gt;
Employee objects.&lt;br /&gt;
It uses four classes.&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70463</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70463"/>
		<updated>2012-11-19T02:47:59Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.JPG]]&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70462</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70462"/>
		<updated>2012-11-19T02:47:14Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.jpg]]&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70461</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w42 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70461"/>
		<updated>2012-11-19T02:44:11Z</updated>

		<summary type="html">&lt;p&gt;Aasawa: /* Facade Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
==Facade Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) 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.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Wrap a complicated subsystem with a simpler interface.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Non-Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
In most of the Pizza centers, orders will be given through phone calls with the customer interacting with the Customer service representative.  In this case, consumers do not have access to the Billing system, Kitchen and delivery department.  The customer service representative acts as an interface and interacts with each of the departments involved in the transaction and ensures that Pizzas are delivered to the consumer.&lt;br /&gt;
&lt;br /&gt;
We can relate this non-software example against the facade design pattern in the following way:&lt;br /&gt;
&lt;br /&gt;
Customer Service representative corresponds to the facade.&lt;br /&gt;
Individual departments involved in the transaction correspond to Sub-systems.&lt;br /&gt;
Another example we can consider is Emergency services. In the event of fire we just inform an Emergency Service operator.  The emergency operator interacts with police, ambulance and fire services and dispatches them. Here the client is shielded from individual emergency services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Software examples&amp;lt;br&amp;gt;&lt;br /&gt;
Web Service Facade Solution Architecture provides an example for Facade design pattern.  In this architectural solution, instead of rewriting legacy applications or customizing those with middleware to connect to other applications one by one, this solution helps create a &amp;quot;facade&amp;quot; for the legacy application.  Other applications are easily &amp;quot;plugged into&amp;quot; this facade.  By modeling a legacy application into its basic functions of create, read, update, and delete and then exposing these functions as Web methods, the Web service facade solution allows other applications to access legacy data by making use of common Web services through standardized protocols.  In this way, Facade decouples layers so that they do not depend on each other which can make it easier to develop, to use and to promote code re-use.&lt;br /&gt;
&lt;br /&gt;
The JIT (Just in-Time) compilers that we use everyday to process the Dotnet code is a prime example of the facade pattern.  JIT compiler performs several lower level functions before converting MSIL into native code, such as verifying whether Microsoft intermediate language (MSIL) code can access the memory locations, checking MSIL code is correctly generated because incorrect MSIL can lead to a violation of the type safety rules, etc.&lt;br /&gt;
&lt;br /&gt;
[[File:Facade-wo.jpg]]&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
A segment of the client community needs a simplified interface to the overall functionality of a complex subsystem.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Facade discusses encapsulating a complex subsystem within a single interface object. This reduces the learning curve necessary to successfully leverage the subsystem. It also promotes decoupling the subsystem from its potentially many clients. On the other hand, if the Facade is the only access point for the subsystem, it will limit the features and flexibility that “power users” may need. The Facade object should be a fairly simple advocate or facilitator. It should not become an all-knowing oracle or “god” object.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1) Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;lt;br&amp;gt;&lt;br /&gt;
2) A hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”.&amp;lt;br&amp;gt;&lt;br /&gt;
3) The new operator considered harmful.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If an application is to be portable, it needs to encapsulate platform dependencies. These “platforms” might include: windowing system, operating system, database, etc. Too often, this encapsulatation is not engineered in advance, and lots of #ifdef case statements with options for all currently supported platforms begin to procreate like rabbits throughout the code.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provide a level of indirection that abstracts the creation of families of related or dependent objects without directly specifying their concrete classes. The “factory” object has the responsibility for providing creation services for the entire platform family. Clients never create platform objects directly, they ask the factory to do that for them.&lt;br /&gt;
&lt;br /&gt;
This mechanism makes exchanging product families easy because the specific class of the factory object appears only once in the application - where it is instantiated. The application can wholesale replace the entire family of products simply by instantiating a different concrete instance of the abstract factory. Because the service provided by the factory object is so pervasive, it is routinely implemented as a Singleton.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adapter Pattern ==&lt;br /&gt;
Convert the interface of a class into another interface clients expect. Adapter lets classes worktogether that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
Intent&amp;lt;br&amp;gt;&lt;br /&gt;
1)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.&amp;lt;br&amp;gt;&lt;br /&gt;
2)Wrap an existing class with a new interface.&amp;lt;br&amp;gt;&lt;br /&gt;
3)Impedance match an old component to a new system.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
1)Object Adapter pattern— relies on one object(the adapting object) containing another (theadapted object).&amp;lt;br&amp;gt;&lt;br /&gt;
2)Class Adapter pattern— implemented withmultiple inheritance&lt;br /&gt;
&lt;br /&gt;
Problem&amp;lt;br&amp;gt;&lt;br /&gt;
An “off the shelf” component offers compelling functionality that you would like to reuse, but its “view of the world” is not compatible with the philosophy and architecture of the system currently being developed.&lt;br /&gt;
&lt;br /&gt;
Discussion&amp;lt;br&amp;gt;&lt;br /&gt;
Reuse has always been painful and elusive. One reason has been the tribulation of designing something new, while reusing something old. There is always something not quite right between the old and the new. It may be physical dimensions or misalignment. It may be timing or synchronization. It may be unfortunate assumptions or competing standards.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
It is like the problem of inserting a new three-prong electrical plug in an old two-prong wall outlet – some kind of adapter or intermediary is necessary.&lt;br /&gt;
&lt;br /&gt;
Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.&lt;br /&gt;
&lt;br /&gt;
Adapter functions as a wrapper or modifier of an existing class. It provides a different or translated view of that class.&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;br /&gt;
&lt;br /&gt;
== Differences n similarities between Adapter and Facade ==&lt;br /&gt;
1)In both the Facade and Adapter pattern we havepreexisting classes.&lt;br /&gt;
&lt;br /&gt;
2)In the Facade, however, we do not have aninterface we must design to, as we do in the Adapter pattern.&lt;br /&gt;
&lt;br /&gt;
3)We are not interested in polymorphic behavior in theFacade, while in the Adapter, We probably am.(There are times when we just need to design to aparticular API and therefore must use an Adapter)&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
4)In the case of the Facade pattern, the motivation isto simplify the interface. With the Adapter, whilesimpler is better,We are trying to design to anexisting interface and cannot simplify things even if a simpler interface were otherwise possible.&lt;br /&gt;
&lt;br /&gt;
Bottom line&lt;br /&gt;
: A Facade simplifies an interface whilean Adapter converts the interface into a preexistinginterface.&lt;/div&gt;</summary>
		<author><name>Aasawa</name></author>
	</entry>
</feed>