JAVA DESIGN PATTERNS

A design pattern ...


PART 1. STRUCTURAL DESIGN PATTERNS
Program 01. Use Bridge Design Pattern for Drawing API.

....


Code: Sphere.java
Program output
Program 02. Use Bridge Design Pattern for Customized List.

....


Code: Sphere.java
Program output
Program 03. Use Adapter Design Pattern for Link to Legacy Code.

....


Code: Sphere.java
Program output
Program 04. Use Adapter Design Pattern for a Requirements Table.

See: ence200.d/java.d/design-pattern-composite1.d/


Code: Sphere.java
Program output
Program 05. Table Adapter Model for Dynamic Display of Stock Market Quotes

See: ence200.d/java.d/design-pattern-adapter2.d ... etc.


Code: Sphere.java
Program output
Program 06. Create Composite Hierarchy of Shapes

See: ence200.d/java.d/design-pattern-composite2.d ... etc.


Code: Sphere.java
Program output
Program 07. Use Composite Hierarchy Pattern for Furniture Layout

See: ence200.d/java.d/design-pattern-composite1.d/


Code: Sphere.java
Program output

PART 2. BEHAVIORAL DESIGN PATTERNS

PROGRAM OUTPUT AND SOURCE CODE

Program 08. Mediator Design Pattern.

....


Standalone Program: Peace.java
Program Output: output
Program 09. Observer Design Pattern.

....


Standalone Program: Peace.java
Program Output: output
Program 10. Observer Design Pattern implemented across Threads

....


Standalone Program: Peace.java
Program Output: output
PART 3. SYSTEM DESIGN PATTERNS
Program 11. Simple Implementation of Model-View-Controller (MVC)

....


Code: Sphere.java
Program output
Program 12. Mediator Implementation of Model-View-Controller (MVC)

....


Code: Sphere.java
Program output
Program 13. MVC Implementation of Temperature

....


Code: Sphere.java
Program output

PART 4. COMPONENT AND SYSTEM FACTORY DESIGN PATTERNS

PROGRAM OUTPUT AND SOURCE CODE

Program 14. A Simple Factory.

Here we present code for a simple factory .....


Code: ...
Program ...
Program 15. A Simplified Component Factory.

Here we present code for a factory of components that can be connected via ports and relationships.


Code: ...
Program ...
Program 16. Abstract Factory Pattern.

An abstract factory pattern .....

Figure 15. Relationship among concrete and interface classes in an abstract factory setup.

  • Client

    Classes in the Client role use various widget classes to request or receive services from the product that the client is working with. Client classes only know about the abstract widget classes. They should have no knowledge of any concrete widget classes.

  • AbstractFactory

    AbstractFactory classes define abstract methods for creating instances of concrete widget classes. Abstract factory classes have a static method shown in the above diagram as getFactory. Another common name for that method is getToolkit. A Client object calls that method to get an instance of a concrete factory appropriate for working with a particular product.

  • ConcreteFactory1 and ConcreteFactory2

    Classes in this role implement the methods defined by their abstract factory superclasses to create instances of concrete widget classes. Client classes that call these methods should not have any direct knowledge of these concrete factory classes, but instead access singleton instances of these classes by calling a method of their abstract factory superclass.

  • WidgetA and WidgetB

    Interfaces in this role correspond to a feature of a product. Classes that implement an interface in this role work with the product to which the interface corresponds.

  • Product1WidgetA, Product2WidgetA

    Classes in this role are concrete classes that correspond to a feature of a product that they work with. You can generically refer to classes in this role as concrete widgets.



Code: ...
Program ...

REFERENCES

  1. ....
  2. .....


Last Modified in April 2012 by Mark Austin
Department of Civil and Environmental Engineering, University of Maryland