<?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=Akoradh</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=Akoradh"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Akoradh"/>
	<updated>2026-06-09T03:57:29Z</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=71206</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=71206"/>
		<updated>2012-11-20T13:19:56Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Adapter 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 &amp;lt;ref&amp;gt;Facade Pattern [http://sourcemaking.com/design_patterns/facade]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It wraps a complicated subsystem with a simpler interface. 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 &amp;lt;ref&amp;gt;Adapter Pattern - [http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Adapter Pattern converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. It wraps an existing class with a new interface. It aims to match an old component to a new system. It strives to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Pattern &amp;lt;ref&amp;gt;Abstract Factory Pattern [http://sourcemaking.com/design_patterns/abstract_factory]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It defines a hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”. 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 &amp;lt;ref&amp;gt;Mediator Pattern [http://sourcemaking.com/design_patterns/mediator]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Mediator Pattern defines 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. It aims to design an intermediary to decouple many peers. It promotes 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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 &amp;lt;ref&amp;gt;Adapter Pattern Example [http://sourcemaking.com/design_patterns/adapter/java/1]&amp;lt;/ref&amp;gt; ==&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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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; &amp;lt;ref&amp;gt;Facade Vs Mediator [http://stackoverflow.com/questions/481984/facade-vs-mediator]&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71205</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=71205"/>
		<updated>2012-11-20T13:17:34Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator Pattern and Facade Pattern [http://stackoverflow.com/questions/481984/facade-vs-mediator] */&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 &amp;lt;ref&amp;gt;Facade Pattern [http://sourcemaking.com/design_patterns/facade]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It wraps a complicated subsystem with a simpler interface. 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 &amp;lt;ref&amp;gt;Adapter Pattern - [http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Adapter Pattern converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. It wraps an existing class with a new interface. It aims to match an old component to a new system. It strives to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Pattern &amp;lt;ref&amp;gt;Abstract Factory Pattern [http://sourcemaking.com/design_patterns/abstract_factory]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It defines a hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”. 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 &amp;lt;ref&amp;gt;Mediator Pattern [http://sourcemaking.com/design_patterns/mediator]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Mediator Pattern defines 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. It aims to design an intermediary to decouple many peers. It promotes 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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; &amp;lt;ref&amp;gt;Facade Vs Mediator [http://stackoverflow.com/questions/481984/facade-vs-mediator]&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71204</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=71204"/>
		<updated>2012-11-20T13:16:58Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Introduction */&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 &amp;lt;ref&amp;gt;Facade Pattern [http://sourcemaking.com/design_patterns/facade]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It wraps a complicated subsystem with a simpler interface. 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 &amp;lt;ref&amp;gt;Adapter Pattern - [http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Adapter Pattern converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. It wraps an existing class with a new interface. It aims to match an old component to a new system. It strives to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Pattern &amp;lt;ref&amp;gt;Abstract Factory Pattern [http://sourcemaking.com/design_patterns/abstract_factory]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It defines a hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”. 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 &amp;lt;ref&amp;gt;Mediator Pattern [http://sourcemaking.com/design_patterns/mediator]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Mediator Pattern defines 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. It aims to design an intermediary to decouple many peers. It promotes 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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; &amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/481984/facade-vs-mediator]&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71203</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=71203"/>
		<updated>2012-11-20T13:16:00Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Introduction */&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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/facade]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It wraps a complicated subsystem with a simpler interface. 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 &amp;lt;ref&amp;gt;Adapter Pattern - [http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Adapter Pattern converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. It wraps an existing class with a new interface. It aims to match an old component to a new system. It strives to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Pattern &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/abstract_factory]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It defines a hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”. 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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/mediator]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Mediator Pattern defines 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. It aims to design an intermediary to decouple many peers. It promotes 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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; &amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/481984/facade-vs-mediator]&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71202</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=71202"/>
		<updated>2012-11-20T13:15:23Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Introduction */&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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/facade]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It wraps a complicated subsystem with a simpler interface. 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 &amp;lt;ref&amp;gt;[Adapter Pattern - http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Adapter Pattern converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. It wraps an existing class with a new interface. It aims to match an old component to a new system. It strives to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Pattern &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/abstract_factory]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It defines a hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”. 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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/mediator]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Mediator Pattern defines 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. It aims to design an intermediary to decouple many peers. It promotes 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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; &amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/481984/facade-vs-mediator]&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71201</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=71201"/>
		<updated>2012-11-20T13:14:37Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/facade]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It wraps a complicated subsystem with a simpler interface. 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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Adapter Pattern converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. It wraps an existing class with a new interface. It aims to match an old component to a new system. It strives to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Pattern &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/abstract_factory]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It defines a hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”. 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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/mediator]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Mediator Pattern defines 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. It aims to design an intermediary to decouple many peers. It promotes 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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; &amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/481984/facade-vs-mediator]&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71200</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=71200"/>
		<updated>2012-11-20T13:13:22Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Introduction */&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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/facade]&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It wraps a complicated subsystem with a simpler interface. 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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/adapter]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Adapter Pattern converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. It wraps an existing class with a new interface. It aims to match an old component to a new system. It strives to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.&lt;br /&gt;
&lt;br /&gt;
== Abstract Factory Pattern &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/abstract_factory]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. It defines a hierarchy that encapsulates: many possible “platforms”, and the construction of a suite of “products”. 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 &amp;lt;ref&amp;gt;[http://sourcemaking.com/design_patterns/mediator]&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Mediator Pattern defines 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. It aims to design an intermediary to decouple many peers. It promotes 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71199</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=71199"/>
		<updated>2012-11-20T12:58:58Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
   //based on some global parameters, set logger as either file or socket or both&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void log( String message ) { &lt;br /&gt;
   //depending on the initialization in initLogger, log the message to a file or socket or both.&lt;br /&gt;
   //handle file input-ouput and socket input-ouput/&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above example, depending on the initialization, the log methods handles the logging of message to either a file or socket or both. It has to have functionality to handle input and output to both file and socket.&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71198</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=71198"/>
		<updated>2012-11-20T12:55:57Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Facade 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;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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          //generate a file logger. Create file if not found. Initialize&lt;br /&gt;
      }&lt;br /&gt;
      public void log( String message ) { &lt;br /&gt;
          //call the file logger's log method&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The log functionality is provided by the file logger. The class Logger hides the handling of files, deletion of files etc. The init method creates a file if not present, defines the size of the file before roll over, initializes some state of Logger. Logger internally calls file logger's log method. It does not define a new functionality. It delegates to existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
               this.loggerName = loggerName;&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out = new PrintStream( new File(&amp;quot;app.log&amp;quot;));&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    client = new Socket(&amp;quot;127.0.0.1&amp;quot;, 1234 );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    dbConnection = Class.forName()... .&lt;br /&gt;
               }&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out.println( message );&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    ObjectOutputStrewam oos = &lt;br /&gt;
                           new ObjectOutputStrewam( client.getOutputStream());&lt;br /&gt;
                    oos.writeObject( message );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    Pstmt pstmt = dbConnection.prepareStatment( LOG_SQL );&lt;br /&gt;
                    pstmt.setParameter(1, message );&lt;br /&gt;
                    pstmt.executeUpdate();&lt;br /&gt;
                    dbConnection.commit();&lt;br /&gt;
               }&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this code, the mediator is the one that contains the business logic to create the appropriate &amp;quot;channel&amp;quot; to log and also to make the log into that channel. He is &amp;quot;creating&amp;quot; the functionality&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71197</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=71197"/>
		<updated>2012-11-20T12:48:19Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
&lt;br /&gt;
      private LoggerImpl internalLogger;&lt;br /&gt;
      private LoggerManager manager;&lt;br /&gt;
&lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          this.internalLogger = manager.getLogger( loggerName ); &lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
          this.internalLogger.debug( message );&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The functionality already exist. The facade only hides it. In this hypothetical case, the LoggerManager handles the creation of the correct logger, and the LoggerImpl is a package private object that has the &amp;quot;debug&amp;quot; method. This way the Facade is not adding functionality he is just delegating to some existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
               this.loggerName = loggerName;&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out = new PrintStream( new File(&amp;quot;app.log&amp;quot;));&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    client = new Socket(&amp;quot;127.0.0.1&amp;quot;, 1234 );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    dbConnection = Class.forName()... .&lt;br /&gt;
               }&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out.println( message );&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    ObjectOutputStrewam oos = &lt;br /&gt;
                           new ObjectOutputStrewam( client.getOutputStream());&lt;br /&gt;
                    oos.writeObject( message );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    Pstmt pstmt = dbConnection.prepareStatment( LOG_SQL );&lt;br /&gt;
                    pstmt.setParameter(1, message );&lt;br /&gt;
                    pstmt.executeUpdate();&lt;br /&gt;
                    dbConnection.commit();&lt;br /&gt;
               }&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this code, the mediator is the one that contains the business logic to create the appropriate &amp;quot;channel&amp;quot; to log and also to make the log into that channel. He is &amp;quot;creating&amp;quot; the functionality&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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;br /&gt;
* http://stackoverflow.com/questions/481984/facade-vs-mediator&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71196</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=71196"/>
		<updated>2012-11-20T12:47:24Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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 ==&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
&lt;br /&gt;
      private LoggerImpl internalLogger;&lt;br /&gt;
      private LoggerManager manager;&lt;br /&gt;
&lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          this.internalLogger = manager.getLogger( loggerName ); &lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
          this.internalLogger.debug( message );&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The functionality already exist. The facade only hides it. In this hypothetical case, the LoggerManager handles the creation of the correct logger, and the LoggerImpl is a package private object that has the &amp;quot;debug&amp;quot; method. This way the Facade is not adding functionality he is just delegating to some existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
               this.loggerName = loggerName;&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out = new PrintStream( new File(&amp;quot;app.log&amp;quot;));&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    client = new Socket(&amp;quot;127.0.0.1&amp;quot;, 1234 );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    dbConnection = Class.forName()... .&lt;br /&gt;
               }&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out.println( message );&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    ObjectOutputStrewam oos = &lt;br /&gt;
                           new ObjectOutputStrewam( client.getOutputStream());&lt;br /&gt;
                    oos.writeObject( message );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    Pstmt pstmt = dbConnection.prepareStatment( LOG_SQL );&lt;br /&gt;
                    pstmt.setParameter(1, message );&lt;br /&gt;
                    pstmt.executeUpdate();&lt;br /&gt;
                    dbConnection.commit();&lt;br /&gt;
               }&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this code, the mediator is the one that contains the business logic to create the appropriate &amp;quot;channel&amp;quot; to log and also to make the log into that channel. He is &amp;quot;creating&amp;quot; the functionality&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71195</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=71195"/>
		<updated>2012-11-20T12:46:53Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
&lt;br /&gt;
      private LoggerImpl internalLogger;&lt;br /&gt;
      private LoggerManager manager;&lt;br /&gt;
&lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          this.internalLogger = manager.getLogger( loggerName ); &lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
          this.internalLogger.debug( message );&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The functionality already exist. The facade only hides it. In this hypothetical case, the LoggerManager handles the creation of the correct logger, and the LoggerImpl is a package private object that has the &amp;quot;debug&amp;quot; method. This way the Facade is not adding functionality he is just delegating to some existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
               this.loggerName = loggerName;&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out = new PrintStream( new File(&amp;quot;app.log&amp;quot;));&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    client = new Socket(&amp;quot;127.0.0.1&amp;quot;, 1234 );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    dbConnection = Class.forName()... .&lt;br /&gt;
               }&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out.println( message );&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    ObjectOutputStrewam oos = &lt;br /&gt;
                           new ObjectOutputStrewam( client.getOutputStream());&lt;br /&gt;
                    oos.writeObject( message );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    Pstmt pstmt = dbConnection.prepareStatment( LOG_SQL );&lt;br /&gt;
                    pstmt.setParameter(1, message );&lt;br /&gt;
                    pstmt.executeUpdate();&lt;br /&gt;
                    dbConnection.commit();&lt;br /&gt;
               }&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this code, the mediator is the one that contains the business logic to create the appropriate &amp;quot;channel&amp;quot; to log and also to make the log into that channel. He is &amp;quot;creating&amp;quot; the functionality&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ==&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71194</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=71194"/>
		<updated>2012-11-20T12:46:24Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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;
== Facade Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Logger { &lt;br /&gt;
&lt;br /&gt;
      private LoggerImpl internalLogger;&lt;br /&gt;
      private LoggerManager manager;&lt;br /&gt;
&lt;br /&gt;
      public void initLogger( String loggerName ) {&lt;br /&gt;
          this.internalLogger = manager.getLogger( loggerName ); &lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
          this.internalLogger.debug( message );&lt;br /&gt;
      }     &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The functionality already exist. The facade only hides it. In this hypothetical case, the LoggerManager handles the creation of the correct logger, and the LoggerImpl is a package private object that has the &amp;quot;debug&amp;quot; method. This way the Facade is not adding functionality he is just delegating to some existing objects.&lt;br /&gt;
&lt;br /&gt;
== Mediator Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void initLogger( String loggerName ) {&lt;br /&gt;
               this.loggerName = loggerName;&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out = new PrintStream( new File(&amp;quot;app.log&amp;quot;));&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    client = new Socket(&amp;quot;127.0.0.1&amp;quot;, 1234 );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    dbConnection = Class.forName()... .&lt;br /&gt;
               }&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      public void debug( String message ) { &lt;br /&gt;
&lt;br /&gt;
               if ( loggerName == &amp;quot;someLogger&amp;quot; ) { &lt;br /&gt;
                    out.println( message );&lt;br /&gt;
               } else if ( loggerName == &amp;quot;serverLog&amp;quot; ) { &lt;br /&gt;
                    ObjectOutputStrewam oos = &lt;br /&gt;
                           new ObjectOutputStrewam( client.getOutputStream());&lt;br /&gt;
                    oos.writeObject( message );&lt;br /&gt;
               } else if( loggerName == &amp;quot;dblog&amp;quot;) { &lt;br /&gt;
                    Pstmt pstmt = dbConnection.prepareStatment( LOG_SQL );&lt;br /&gt;
                    pstmt.setParameter(1, message );&lt;br /&gt;
                    pstmt.executeUpdate();&lt;br /&gt;
                    dbConnection.commit();&lt;br /&gt;
               }&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this code, the mediator is the one that contains the business logic to create the appropriate &amp;quot;channel&amp;quot; to log and also to make the log into that channel. He is &amp;quot;creating&amp;quot; the functionality&lt;br /&gt;
&lt;br /&gt;
== Differences and Similarities ===&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). Facade is an structural pattern, that is it describes the composition of the objects, while the mediator is an behavioral, that is , it describes the way the objects interact.&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71030</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=71030"/>
		<updated>2012-11-20T01:51:16Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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;
Mediator Pattern is used to avoid the direct dependencies between reusable pieces of software i.e if one of the components changes, then all components which are directly connected to it changes. One of the important example is the resources permission in unix. There are three categories of permissions - owner, group and others. Some users with similar characteristics are formed into a group. 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. 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71028</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=71028"/>
		<updated>2012-11-20T01:40:22Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Adapter 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 class is a wrapper which modifies an existing class. It provides an alternate view of that class. In cases where a third party component is readily available and provides functionality that needs to be used, but the interfaces exposed by the component does not have an exact match with the system that is being developed, adapter classes can be used. The mismatch can be diverse such as the way arguments are handled, some assumptions about the underlying implementations, physical dimensions, misalignment, timing or synchronization etc. 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;
&lt;br /&gt;
Adapter Pattern creates an intermediate class that maps the one component to other. The calls to methods on the Adapter object is redirected by the adapter 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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71027</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=71027"/>
		<updated>2012-11-20T01:39:32Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
  public OrderId placeOrder(...) {&lt;br /&gt;
    //convert order id from int to type 'OrderId' and return&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71026</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=71026"/>
		<updated>2012-11-20T01:39:10Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Adapter 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;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, in the Facade example, assume that the user of OrderFacade needs to obtain order id in a different representation. To handle such scenario, a new adapter class OrderFacadeAdapter is defined. It implements all the methods of the OrderFacade and in each method where order id is referenced,  it makes necessary changes to convert order id from one form to other and invoke other methods of the subsystem.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public Class OrderFacadeAdapter {&lt;br /&gt;
 public OrderId placeOrder(...) {&lt;br /&gt;
 //convert order id from int to type 'OrderId' and return&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=71025</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=71025"/>
		<updated>2012-11-20T01:38:34Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;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 OrderFacadeAdapter {&lt;br /&gt;
 public OrderId placeOrder(...) {&lt;br /&gt;
 //convert order id from int to type 'OrderId' and return&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70950</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=70950"/>
		<updated>2012-11-20T00:32:09Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Differences and similarities between Adapter and Facade */&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;
&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70949</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=70949"/>
		<updated>2012-11-20T00:31:49Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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 between Adapter and Facade ==&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;
&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70947</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=70947"/>
		<updated>2012-11-20T00:30:27Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Differences n similarities between Adapter and Facade */&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 between Adapter and Facade ==&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;
&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70946</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=70946"/>
		<updated>2012-11-20T00:30:16Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Adapter 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 n similarities between Adapter and Facade ==&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;
&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70942</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=70942"/>
		<updated>2012-11-20T00:28:52Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Differences n similarities between Adapter and Facade */&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;
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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70941</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=70941"/>
		<updated>2012-11-20T00:28:30Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;
=&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;
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;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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70940</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=70940"/>
		<updated>2012-11-20T00:28:00Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;
=&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;
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;
=&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70935</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=70935"/>
		<updated>2012-11-20T00:26:25Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;
=&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;
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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Mediator_1.gif&amp;diff=70933</id>
		<title>File:Mediator 1.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Mediator_1.gif&amp;diff=70933"/>
		<updated>2012-11-20T00:24:39Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70932</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=70932"/>
		<updated>2012-11-20T00:21:59Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;
=&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;
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;
[http://sourcemaking.com/files/sm/images/patterns/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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70930</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=70930"/>
		<updated>2012-11-20T00:19:15Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;
=&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;
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;
=&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70928</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=70928"/>
		<updated>2012-11-20T00:15:10Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;
=&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70925</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=70925"/>
		<updated>2012-11-20T00:13:22Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Adapter 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;
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|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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70900</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=70900"/>
		<updated>2012-11-19T23:36:54Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Adapter 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;
[[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;
=&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70897</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=70897"/>
		<updated>2012-11-19T23:31:54Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Adapter 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;
[[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;
The draw method for the Line and the Rectangle differs in their implementation. However, the callers of the draw method need not care of the internals of drawing a shape. Adapter pattern specifies to create a new interface (Shape) and each of the Objects that implement their own draw method. The caller then just invokes &amp;quot;shape.draw&amp;quot;.&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;
=&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70877</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=70877"/>
		<updated>2012-11-19T23:13:00Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Mediator 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;
Class line implements Shape {&lt;br /&gt;
  void draw(...) {...}&lt;br /&gt;
}&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  void draw(...) {...}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The draw method for the Line and the Rectangle differs in their implementation. However, the callers of the draw method need not care of the internals of drawing a shape. Adapter pattern specifies to create a new interface (Shape) and each of the Objects that implement their own draw method. The caller then just invokes &amp;quot;shape.draw&amp;quot;.&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().&lt;br /&gt;
&lt;br /&gt;
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;
== 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;
=&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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70876</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=70876"/>
		<updated>2012-11-19T23:12:49Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* Abstract Factory 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;
Class line implements Shape {&lt;br /&gt;
  void draw(...) {...}&lt;br /&gt;
}&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  void draw(...) {...}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The draw method for the Line and the Rectangle differs in their implementation. However, the callers of the draw method need not care of the internals of drawing a shape. Adapter pattern specifies to create a new interface (Shape) and each of the Objects that implement their own draw method. The caller then just invokes &amp;quot;shape.draw&amp;quot;.&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().&lt;br /&gt;
&lt;br /&gt;
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;
== 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70874</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=70874"/>
		<updated>2012-11-19T23:12:13Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;
&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;
Class line implements Shape {&lt;br /&gt;
  void draw(...) {...}&lt;br /&gt;
}&lt;br /&gt;
Class Rectangle implements Shape {&lt;br /&gt;
  void draw(...) {...}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The draw method for the Line and the Rectangle differs in their implementation. However, the callers of the draw method need not care of the internals of drawing a shape. Adapter pattern specifies to create a new interface (Shape) and each of the Objects that implement their own draw method. The caller then just invokes &amp;quot;shape.draw&amp;quot;.&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().&lt;br /&gt;
&lt;br /&gt;
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;
== 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&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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70860</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=70860"/>
		<updated>2012-11-19T22:55:05Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;
&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&amp;lt;/b&amp;gt; =&lt;br /&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.&amp;lt;br&amp;gt;&lt;br /&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. 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;
Two types of adapter patterns&amp;lt;br&amp;gt;&lt;br /&gt;
* Object Adapter pattern — relies on one object(the adapting object) containing another (theadapted object)&lt;br /&gt;
* Class Adapter pattern — implemented with multiple inheritance&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;
== 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&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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70849</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=70849"/>
		<updated>2012-11-19T22:44:32Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;
[[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&amp;lt;/b&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;
== Example ==&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;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70846</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=70846"/>
		<updated>2012-11-19T22:44:03Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;
[[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&amp;lt;/b&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;
== example ==&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;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70840</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=70840"/>
		<updated>2012-11-19T22:42:47Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: /* 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;
[[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&amp;lt;/b&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;
== example ==&lt;br /&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;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Abstract Factory 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70836</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=70836"/>
		<updated>2012-11-19T22:41:09Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &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&amp;lt;/b&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;
== example ==&lt;br /&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;
&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;
&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;
=&amp;lt;b&amp;gt;Abstract Factory 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70835</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=70835"/>
		<updated>2012-11-19T22:40:35Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &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&amp;lt;/b&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;
==example==&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;
&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;
&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;
=&amp;lt;b&amp;gt;Abstract Factory 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70680</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=70680"/>
		<updated>2012-11-19T20:21:07Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &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&amp;lt;/b&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;
=&amp;lt;b&amp;gt;Abstract Factory 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70671</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=70671"/>
		<updated>2012-11-19T20:17:07Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &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;
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;
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;
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;
&amp;lt;b&amp;gt;Intent&amp;lt;/b&amp;gt;&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;
==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;
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;
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&amp;lt;/b&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;
=&amp;lt;b&amp;gt;Abstract Factory 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;
=&amp;lt;b&amp;gt;Mediator 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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70663</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=70663"/>
		<updated>2012-11-19T20:06:23Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &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. Customer Service representative corresponds to the facade. Individual departments involved in the transaction correspond to Sub-systems.&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;
[[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>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70444</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=70444"/>
		<updated>2012-11-19T01:40:46Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &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;
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;
==Mediator Pattern==&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70443</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=70443"/>
		<updated>2012-11-19T01:37:01Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &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;
==Abstract Factory Pattern==&lt;br /&gt;
&lt;br /&gt;
==Mediator Pattern==&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70442</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=70442"/>
		<updated>2012-11-19T01:36:14Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt;Introduction&amp;lt;/b&amp;gt; =&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w42_aa&amp;diff=70441</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=70441"/>
		<updated>2012-11-19T01:33:22Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: Created page with &amp;quot;2w42. Facade pattern and the related patterns (Adapter, Abstract Factory, Mediator)&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;2w42. Facade pattern and the related patterns (Adapter, Abstract Factory, Mediator)&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=70440</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=70440"/>
		<updated>2012-11-19T01:32:53Z</updated>

		<summary type="html">&lt;p&gt;Akoradh: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2012/Table_Of_Contents]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w3_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w26 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w11_aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w15 rr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w33 pv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w20_aa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w14_bb]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w21_ap]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w13_sm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w4_sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w25_nr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w12_sv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w7_ma]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w6_ar]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w32_mk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w10_rc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w70_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w67_sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w40_sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w22_sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w-1w65_am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w59_bc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w60_ns]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b 2w47 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w69_as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w39_ka]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w36_av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w37_ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w43_iv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w53_iv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w63_sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w49_ps]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w52_sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w28_dh]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 2w41 dc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_1w59_nm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_1w61_ps]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_2w57]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_2w42_aa]]&lt;/div&gt;</summary>
		<author><name>Akoradh</name></author>
	</entry>
</feed>