You are on page 1of 4

University of Sargodha

Department of Computer Science

Course Code: SE-4345 Software Design Patterns


Class: PPP BSSE 8th Session: 2016-20
Exam: Mid Term Assigning Date: 08/04/2020
Total Marks: 30 Submission Date: 15/04/2020
Name: Muhammad Shahbaz Reg: 15-uglc-948

“Note
 Attempt all questions.
 Do not copy and paste. Write in your own words
 Marks should be evaluated based on plagiarism’s report and quality.

1. Compare and contrast between following Design Patterns. Draw a table for
comparison. (10)

 Prototype Design pattern


 Singleton Design Pattern

Compare Prototype Design pattern and Singleton Design pattern.”

Prototype Design Pattern Singleton Design pattern

 Deal with one Only instance of class  Deal with new objects by copying
at any time. or cloning existing object
 Create the instance of class on  No demand, but shallow and deep
demand cloning occur
 Base on Lazy initialization concept  Base on Expensive initialization

 Prototype is single because it does not  But in the side of Singleton class is
essential class but only object needed.

 Prototype is less flexible  Critical maintain the flexibility of


Singleton
 Adding and removing product at run  This design pattern not have
time attributes at run time toad product.
 “Abstract factory Design pattern
 Builder Design Pattern

Compare Builder Design pattern and Abstract Factory Design pattern.”

Abstract Factory DP Builder Design pattern

 Provide and interface for creating  Deal with creating step by step of
object of related families. object and return final object.
 No specify the Concrete Classes  It implies only one type of creating
object
 It deals with simple creating of object  It deals with complex creating of
object

 Abstract Factory concern to return the  Builder Return the product as final
product as soon as possible product or final step.

 This design pattern is appropriate  This pattern appropriate when


when you need, hierarchy of creating object more complex than just
object. calling object.

 Promoting consistency among  Requires creating a separate


products Concrete-Builder for each different
type of Product.
 Isolation of concreate classes
 It deals easily with new product by
 Difficulties to support coming new creating new builder
type of product
2. “Write invariant, precondition and postcondition on following Class diagram, using
object constraint language (OCL). (Note: each type has three constraints. (10)

Invariant:
1. Context product inv quantityOverZero: Self.Quantity>0

2. Context Item inv priceOverZero: Self.Price>0

3. Context Person inv firstnameNotNull: Self.firstname!=Null

Pre-Condition:
1. Context personCreator::CreatePerson(newPerson) pre: Person.name=>forAll(x|
x.name!=Person.name)

2. Context Oder::create() pre: Self.Status==0

3. Context Pre::process()pre: Self.Status==Ordered

Post-Condition:
1. Context cancelOrder::cancel(newPrice,newQuantity) post:
Item.quantity=newQuantity,
Item.price=newPrice

2. Context companyDelete::DeleteCompany(oldCompany) post:


DeleteCompany==oldCompany

3. Context personCreater::CreatePerson(newFirstName,SecondName) post:


Person.fisrtname=newFisrtName,
Person.secondname=newSecondName”
___________________________________________________________________________

3. “Explain with logical reasoning


a. In early design stages, why we are picked or choose APIs, different diagrams and
sketches which are drawn through pencil-paper over software prototypes? Give
reasons?”
Ans. Professional Designer use sketch prototype for there product but, At early stages
developer who have little knowledge of prototyping the use API’s for he Following reason:
 It saves the time
 Less chances of mistake.
 Enhance the Knowledge of understanding and skills for the future
 Mistake are shown in the API during prototyping unlike in pencil paper sketch.
 Rapidly develop ate early stages.
 Must be edit and test before finishing.
 Ease for us to use the platform like many papers, buttons and many functions.
 Various interfaces and comfortable at early stages.
b. “Characterize the following design patterns as behavioral, structural, and
creational. Explain with reason”

i. Ans. It is behavioral Design pattern. Because, here behavior of the application


or function of the application must be noticeable.it is behavior due to following
reason.

 Record the behavior or activities more than one screen. Like behavior
concern with communication between objects.

 Screen not able to similar appearance. Like behavior pattern increase


flexibility through communication.

ii. Ans. This case study deal with creational Design Pattern. Because according to
scenario there is user choice and it may apply factory method which is creational
design pattern. Following reason:
 Creational deal with way of creating object
 When decision made at time creational pattern use.
 Allow user to pick categories
 Portfolio depend on user choice
These all reason tells that this is creational design pattern.

c. “For this question you can use your knowledge about design patterns and for
given situation recommend a solution. State the name of pattern(s) that can solve
this situation, how this pattern(s) is used to solve. You do not need to provide
pattern details”

i. Ans. This case deal with the Factory Design Pattern due to some following
reason:
 Factory lets the subclass to create which type of object. Here all depend to
user choice.
 It deals with simple creating of object, when user choose any operation like
“Train or bus” abstract class create object and return.
 Factory concern to return the product as soon as possible (in case of “bus
Train or Flight Travel”).

ii. Ans. This case deal with the Builder Design Pattern due to some following
reason:
 Builder create step by step object and return the final object (in this case
build” wall, roof , basement” and give final result as building.)
 Builder Design Pattern concern to return Final Produce (in case of this
“Building is final Product”).

You might also like