Css422 - Design Patterns

Only available on StudyMode
  • Download(s): 246
  • Published: November 10, 2010
Read full document
Text Preview
Design Patterns

Design Patterns
The purpose of this paper is to compare and contrast five design patterns. An explanation of design patterns begins the paper. After the explanation are sections on Adapter, Facade, Factory Method, Observer, and Proxy. A conclusion completes the paper. Definition and Explanation

According to SourceMaking (2010), "In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design" (para. 1). Transforming a design pattern directly into code is not possible as it is not a complete design. Rather, a design pattern is a description or template for how to solve a problem with use in many different situations (SourceMaking, 2010).

Design patterns concern themselves with three primary uses or families. Families include creational design patterns, structural design patterns, and behavioral design patterns. Creational design patterns revolve around class instantiation. Structural design patterns are specific to class and object composition. Behavioral design patterns are about object communication. Adapter

Adapter is a structural design pattern. According to SourceMaking (2010), "Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system" (Discussion, para. 3). In other words, Adapter allows for component reuse when implementing a new system. An analogy is attaching a composite to HDMI adapter between a gaming system and an HDTV. Without the adapter, the ability to display video in HD quality is not possible. Adapter works the same way, allowing for functionality between otherwise incompatible systems. Another word for Adapter is wrapper. In comparing with the Facade design pattern the difference is Facade defines a new interface and Adapter reuses and existing interface (SourceMaking, 2010). Facade

Facade, like Adapter is a wrapper and a structural design pattern. Unlike Adapter, the intent of Facade is to create an interface rather than reuse an existing interface. The interface Facade creates is a wrapper around a subsystem. According to SourceMaking (2010), "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" (Discussion, para. 1). A real-world example of Facade is placing an order for cable television over the telephone. The customer service representative for the cable provider acts as a Facade, providing an interface between the sales department, the billing department, and service department. Factory Method

The intent of Factory Method is, according to SourceMaking (2010), "Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses" (Intent, para. 1). Factory Method delegates the creation of detailed behavior to subclasses, defining standard and generic behavior as a superclass (SourceMaking, 2010). An everyday example of Factory Method is injection molding. According to SourceMaking (2010), "Manufacturers of plastic toys process plastic molding powder, and inject the plastic into molds of the desired shapes. The class of toy (car, action figure, etc.) is determined by the mold" (Example, para. 1). Unlike Adapter and Facade, Factory Method is a creational design pattern. Observer

Observer is a behavioral design pattern. Observer serves the purpose of automatically updating objects when a subject object's state changes. The behavior is a "pull" interaction model meaning each object pulls changes and incorporates the changes. According to SourceMaking (2010), "The Observer defines a one-to-many relationship so that when one object changes state, the others are notified and updated automatically" (Example, para. 1). An example of Observer is an...
tracking img