0% found this document useful (0 votes)
4 views27 pages

SDA-10 lecture

Data structure and algorithm lecture

Uploaded by

mhashir3052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views27 pages

SDA-10 lecture

Data structure and algorithm lecture

Uploaded by

mhashir3052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Lecture-10

Software Design & Architecture


(SDA)
Muhammad Jamil
Software Developer
jamil.57@Hotmail.com
Mediator Pattern

• Mediator pattern is used to reduce communication


complexity between multiple objects or classes.
• This pattern provides a mediator class which normally
handles all the communications between different
classes and supports easy maintenance of the code by
loose coupling.
• Mediator pattern falls under behavioral pattern category.
Mediator Pattern
• We are demonstrating mediator pattern by example of a
chat room where multiple users can send message to
chat room and it is the responsibility of chat room to
show the messages to all users.
• We have created two
classes ChatRoom and User. User objects will
use ChatRoom method to share their messages.
• MediatorPatternDemo, our demo class, will
use User objects to show communication between them.
Mediator Pattern
Mediator Pattern
Step 1
Create mediator class.
Mediator Pattern
Step 2
Create user class.
Mediator Pattern
Step 3 & 4
Structural Design Pattern
Composite Pattern
Composite Pattern

• Composite pattern is used when we need to treat a group


of objects in similar way as single object
• Composite pattern composes objects in terms of a tree
structure to represent part as well as whole hierarchy
• This type of design pattern comes under structural design
pattern as this pattern creates structure of group of
objects
Composite Pattern

Implementation
• We have a class employee which acts as composite
pattern actor class
• Composite pattern Demo, our demo class use employee
class to add department level hierarchy and print all
employees
Composite Pattern
Implementation
Step # 1
Create Employee class having list of Employee objects
Step # 2
Use the Employee class to create and print employee hierarchy
Step # 3
Verify the output
Introduction to Decorator Pattern

• Decorator pattern allows a user to add new


functionality to an existing object without
altering its structure.
• This type of design pattern comes under
structural pattern as this pattern acts as a
wrapper to existing class
• This pattern creates a decorator class which
wraps the original class and provides
additional functionality keeping class methods
signature intact
Introduction to Decorator Pattern

• We're going to create a Shape interface and


concrete classes implementing the
Shape interface
• We will then create an abstract decorator class
Shape Decorator implementing
the Shape interface and having Shape object
as its instance variable.
• Red Shape Decorator is concrete class
implementing Shape Decorator.
• Decorator Pattern Demo, our demo class will
use Red Shape Decorator to decorate
Shape objects
Decorator Pattern(additional
features like time, button hover
cover sound etc.
Decorator Pattern
Decorator Pattern
Decorator Pattern
Decorator Pattern
Decorator Pattern
Introduction to Adaptor Pattern

• Adapter pattern works as a bridge


between two incompatible interfaces
• This type of design pattern comes under
structural pattern as this pattern
combines the capability of two
independent interfaces
• This pattern involves a single class which is
responsible to join functionalities of
independent or incompatible interfaces
Introduction to Adaptor Pattern

• A real life example could be a case of card


reader which acts as an adapter between
memory card and a laptop
• You plugin the memory card into card reader
and card reader into the laptop so that
memory card can be read via laptop.
Summary

• Structural Design Pattern


• Introduction to composite pattern
• Composite Pattern Steps
• Introduction to Adaptor Pattern
• Adaptor Pattern Steps
• Introduction to Decorator Pattern
• Decorator Pattern Steps
Thank You!

You might also like