Structural Design Patterns in Software Engineering

Today's article on Structural design patterns is the fourth and the last article on design patterns in Software Engineering, read the earlier articles here:

What to you mean by Structural Patterns in Software Engineering?

Structural design pattern are way to describe how classes and objects are composed in application to form larger structure. Structural design pattern simplifies the structure of the application by identifying the relationships. It basically focuses on how classes are related to each other via inheritance and how one class is composed from the other.

Advantages of Structural design pattern

  • The efficiency of the application increases when we use design pattern.
  • Reusability of the application also increases through the use of structural design pattern.
  • Through the use of design pattern in the application, the structure of the application becomes cleaner and simpler- interfaces become easier to understand.

Different types of structural design pattern

1. Adapter Pattern

The adapter pattern is a type of structural pattern which connects two related interface. It is the device adapter which connects the two devices together. Let us take real world example. Electric sockets in our houses are of different sizes and shapes. Let’s take the example of a socket of 20 Ampere. A 10 Amp socket cannot fit a 20 Amp plug. This is why we use an adapter to connect the two. The adapter can be called a connector here.

2. Bridge Pattern

Bridge pattern is basically used for separating the interface from its implementation. Doing this gives flexibility.
The best example of this is the use of switch board.The switch board is a bridge in which there is ON/OFF buttons for fans and tube light. The functionality can be used to switch On the fan with help of ON button on switch board and Switch Off the fan using OFF button on the switch board. We have two more device tubelight and AC whose functionality is also managed through switch button.
Lets understand this with the help of example:
Public interface SwitchBridge
 {
   void switchOn();
   void switchOFF();
 }
Public class Fan implements SwitchBridge
 {
    void switchOn()
  {
     System.out.println(“FAN IS SWITCHED OFF USING SWITCH BOARD”);
   }
  void switchOFF()
 {
    System.out.println(“FAN IS SWITCHED ON USING SWITCH BOARD”);
  }
  } Public class Fan implements SwitchBridge
  {
     void switchOn()
   {
      System.out.println(“TUBELIGHT IS SWITCHED OFF USING SWITCH BOARD”);
   }
  void switchOFF()
 {
     System.out.println(“TUBELIGHT IS SWITCHED ON USING SWITCH BOARD”);
  }
}
 Public class AC implements SwitchBridge
 {
    void switchOn()
    {
      System.out.println(“AC IS SWITCHED OFF USING SWITCH BOARD”);
     }
   void switchOFF()
  {
     System.out.println(“AC IS SWITCHED ON USING SWITCH BOARD”);
   }
}

3. Composite Pattern

Composite pattern is a kind of Structural design pattern and is used when we have to represent a part-whole hierarchy. The collection of the object is stored in the class.

4. Facade Pattern

Façade Design pattern hides the complexities of the system. A separate interface is used for hiding the complexities of the system and delegate the call to the system classes.
Façade patterns are allowed in following scenarios
  • When we want a simple system from a complex system. Subsystem becomes complex as we start developing it. The subsystems can be reused and are easier to use. A façade pattern provides simple view to the subsystem.
  • There are many dependencies between clients and implementation class of an abstraction.
  • We can easily layer our system with the help of façade. The view and complex logic gets separated from each other.

5. Flyweight Pattern

Flyweight pattern is basically used to reduce the number of objects created and used in the application. It is generally useful to minimize the usage of memory and increase performance. When no matching object is found, an existing similar kind of objects can be reused by flyweight pattern.

6. Proxy Pattern

A class represent the functionality of another class is basically proxy pattern.
Proxy patterns are applicable in below references:
  • Remote proxy – It basically provides a local representation for an object in a different address space.
  • A virtual proxy – It basically helps in creating expensive objects
  • Protection proxy- It is helpful when the objects have different access rights.

Read More:
Abstraction vs Encapsulation in OOPs with example
Advantages And Features Of Object Oriented Programming

Copyright © ianswer4u.com

0 Reactions:

Post a Comment