Assignment 1 70068027
Assignment 1 70068027
Mohid-ur-
Student Name Program BSSE
Rehman
Title of
ID 70068027 Assignment 1
Assignment
Section T Due Date 11/March/2021
Submission
Course Name Design Pattern 10/March/2021
Date
Question:-
Why are design patterns important? Support your answer with a couple of
examples.
Answer:-
Design Pattern: - Design patterns are the general reusable solution of reoccurring problems in
the application-programming environment.
Programmers often run into the same problem over and over again. Instead of everyone coming
up with his/her own solution to a common problem, we prefer to use a best-practice type solution
that has been already documented and proven to work. We cannot copy paste design pattern in
our code design pattern just represent an idea of problem we should write implementation of that
pattern and then use in our code.
Real life example:- lets we take an example of TEA if someone like tea a lot and he also don’t
know how to make it perfect that’s the main problem for him and it happened with most of the
people. Therefore, some expert person already gave recipe how to make tea perfect. RECIPE
work as a design pattern person just use this designed recipe and solve his problem
Also, we take some example of any other food which recipes already available so if he/she don’t
know how to cook it’s problem for him and recipe work as a design pattern he/she used it and
solved his/her problem.
That is why design patterns are important they help us to solve reoccurring problems correctly
and fast
Question 2:
All kind of patterns can be divided into three kinds:
• Creational
• Structural
• Behavioral
Briefly discuss each kind of the above mention pattern types and establish key differences
among all three.
Answer: -
Creational: - Creational patterns deal with the method of object creation while hiding the
creation logic. Moreover, they are used in situations when the basic form of object creation can
increase design problems or codebase complexity. Instead of instantiating objects directly using
the ‘new’ operator. This gives the program more flexibility in deciding which objects need to be
created for a given use case.
Prototype, builder etc. are creational patterns
Structural: - Structural design patterns deal with class and object composition these design
identifying an easy way to understand how to make connections between class and objects. The
concept of inheritance is used to compose interfaces and define ways to compose objects to
obtain new functionality.
Bridge, decorator etc. are structural patterns.
Behavioral: - These design patterns are specifically concerned with communication between
objects and these patterns explains how objects communicate. It explains how different objects
and classes send messages to each other to make things and how the stages of work are divided
between different objects.
Mediator, observer etc. are behavioral patterns
Whereas, creational patterns are used to describe moment time instant of creation
Structural patterns describe approximately static structures
Behavioral Patterns describe flow or process
------------------------------------------------------------