CREATIONAL DESIGN PATTERNS IN DETAILED DESIGN AND DESIGN LOGIC PATTERNS

Software Design Patterns

Abstract Factory

Definition

The abstract factory pattern is a creational design software pattern that provides a means to encapsulate a group of individual factories or units sharing common characteristics but without specifying actual classes. A factory is location of real class in the code where objects are constructed.

Problem

Abstract factory class declares only interface for creating products whereas it is the task of concrete product class to actually create products. This might cause concrete factory to override existing factory methods.

Benefit

The pattern may be used to insulate object creation from their current usage and further create families of related objects without depending on actual classes. The benefit from this is that it allows creation of new derived types without requiring any changes to code that use base class.

Factory Method

Definition

Factory method is a popular creational design pattern in object-oriented programming and it helps to put into practice the concept of factories. The design pattern may be specifically used to deal with problem of object creation without specifying exact number of object classes that would be created. This method is used when object creation and reuse becomes impossible without duplication of code (Otero, pp.188-189).

Problem

  • Refactoring of existing classes of using factories breaks changes existing clients.
  • This pattern relies on private constructor that limits extension of class and
  • Inherited constructors are required to be invoked by sub-classes which cannot be done if constructor is private

Benefit

  • The essence of this pattern is to define interface an object by letting the interface decide which class needs to be instantiated
  • They are common in frameworks and toolkits where objects are created using library codes which may further be sub-classed

Builder

Definition

It is a popular object creation software design pattern that aims to find solution to telescopic constructor anti pattern. This phenomenon of anti-pattern occurs when increase of constructor object parameter leads to list of exponential constructors. Thus, instead of using frequent constructors the builder pattern uses another builder object that takes initialization parameter sequentially returns resultant output object at once.

Problem

  • It is difficult to differentiate between builder class and abstract factory class patterns as they are practically very similar
  • It requires common interface for products belonging to common classes

Benefit

  • It is useful when system requires allowing different representations for objects that are being created
  • It is also applicable when object creation algorithm is complex and independent from its constituent parts

Prototype

Definition

It is a creational design pattern in the field of software development that is popularly used when object type is determined from prototype instance cloned for producing new objects. Abstract classes are required to implement this pattern that uses pure virtual clone method (Otero, pp.201-203).

Problem

  • Using a lot of prototypes that are dynamically created and destroys requires creation of registry called prototype manager
  • Initialization and implementation of clone operations may be complex in certain situations

Benefit

  • It is beneficial when sub-classes of object creator can be avoided in client application
  • It is useful when inherent cost of creating new object is expensive to implement a given application

Singleton

Definition

In software engineering, this design pattern restricts classes to be instantiated to objects. The pattern is very useful when one object needs to coordinate actions across system. The pattern generalizes systems that operates more efficiently with single object and restricts instantiation up to limited number of objects.

Problems

  • Multi-threading use must be carefully synchronized for robust application implementation
  • Serialization interface have to be implemented using read resolve method to avoid having multiple objects

Benefits

  • Protected constructor may be used to permit subclasses
  • Provides a global access point to objects

Domain Logic Pattern

Transaction Script

Definition

It organizes business logic by particular routines handling single request from presentation layer and is the most common way of writing applications for beginners. Language semantics can be used to identify and express tasks and common routines may be broken into sub-routines. Transcripts are generally organized as global functions or classes.

Problems

  • Procedural programming code
  • It is best suited for simple business logic scenarios where business logic is straight forward

Benefits

  • A single file may contain multiple transcripts at once
  • It is simple procedural model and very easy to understand

Domain Model

Definition

They help to organize domain logic into well defined entities containing both data and behavior. Conceptually each entity class represents single entity in data layer and this model creates hierarchy of inter-related objects that can interact by triggering behavior.

Problems

  • Requires focusing on behaviors of entities instead of regular routines
  • It does not work effectively with relational databases

Benefits

  • Enables full power OOP concept
  • Handles domain complexities more efficiently compared to transaction scripts

Table Module

Definition

It is a database centric approach where all business logic is organized in the region of database tables. It is very useful when application uses tabular data frequently such as SQL call and hence useful for flexible database architectures.

Problems

  • It may include queries as factory methods using Table Data Gateway class
  • Table module may be instance or static method

Benefits

  • A single class can be used to encapsulate all domain logic for all view or table
  • Implementation is relatively simple since data translation is not required

Service Layer

Definition

This pattern is applied with service oriented design approach that aims to organize services within service inventory of logical layer sets. The services are categorized in a particular layer on the basis of functionality.

Problems

  • It should not be used when business logic of service layer has single client
  • Adding an interface or service layer is time consuming

Benefits

  • Defines common application operation sets for different clients and further coordinates each response
  • Helps to reduce conceptual overheads
  • Helps to manage service inventory belonging to same layer

 


Works Cited

  • Fowler, Martin. Patterns of Enterprise Application Architecture. United States: Pearson Education Inc, 2012. Print.
  • Otero, Carlos. Software Engineering Design: Theory and Practice. United States: CRC Press, 2012. Print.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>