0% found this document useful (0 votes)
63 views8 pages

CS711 Final Term Paper (Naina Malik)

This document contains questions and answers related to design patterns and object-oriented principles. It discusses the differences between vectors and arrays, differences between design patterns and principles, how to apply the prototype pattern to simulate a travel agency managing trips with different packages, benefits of the iterator pattern, and when to use patterns like factory, singleton, and facade. It also includes class diagrams and code examples.

Uploaded by

mraza17
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)
63 views8 pages

CS711 Final Term Paper (Naina Malik)

This document contains questions and answers related to design patterns and object-oriented principles. It discusses the differences between vectors and arrays, differences between design patterns and principles, how to apply the prototype pattern to simulate a travel agency managing trips with different packages, benefits of the iterator pattern, and when to use patterns like factory, singleton, and facade. It also includes class diagrams and code examples.

Uploaded by

mraza17
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/ 8

CS711 Final Term Papers

Q: 1. Differences between a Vector and an Array

✓ A vector is a dynamic array, whose size can be increased, where as an array size cannot be
changed (static).

✓ Reserve space can be given for vector, where as for arrays cannot.
A vector is a class where as an array is not.

✓ Vectors can store any type of objects, where as an array can store only homogeneous values.

✓ As Vectors are dynamically-allocated; they offer a relatively memory-efficient way of handling


lists whose size could change drastically.

✓ Vectors aren’t declared to contain a type of variable.

✓ Array is declared to store a certain number of a certain kind of variables. (page no 280)

Q: 2 Differentiate between Design Patterns and Design Principles


✓ Design principles are guidelines that aim to achieve the desirable goals of a good design. Design
patterns are solution for common design problems that use design principles to achieve these
desirable goals of a good design.

✓ Design principles are applied collectively to solution logic in order to shape it. Design
principles are used to create the software with different levels/ classification.
✓ Design patterns provide solutions to common problems encountered when applying design
principles—and—when establishing an environment suitable for implementing logic
designed in accordance with service-orientation principles.
✓ In many ways, design principles and patterns are alike. Both provide design guidance in
support of achieving overarching strategic goals.

1
Q: 3Difference between design pattern and framework

Q: 4 Lets' assume we have to develop an application for a travel agency. The travel agency is
managing each trip. All the trips contain common behavior but there are several packages. For
example each trip contains the basic steps:
i. The tourists are transported to the holiday location by plane/train/ships.
ii. Every day they are visiting some place.
iii. They are returning back home.
Our task is to design and implement a system which should simulate the mentioned
requirements.

Prototype Design Pattern will be used for above situation


Class diagram for solution:

2
Java Code
i. Trip Class
public class Trip {
// This method can’t be overridden by the sub class but we are calling abstract method inside it.
//This will keep intact the outline of the algorithm.
public final void performTrip(){
doComingTransport();
doDayA();
doDayB();
doDayC();
doReturningTransport
}
public abstract void doComingTransport();
public abstract void doDayA();
public abstract void doDayB();
public abstract void doDayC();
public abstract void doReturningTransport();
}
ii. PackageA class
public class PackageA extends Trip
{

3
public void doComingTransport()
{
System.out.println("The tourists are comming by air ...");
}
public void doDayA() {
System.out.println("The tourists are visiting the garden ...");
}
public void doDayB() {
System.out.println("The tourists are going to the museum ...");
}
public void doDayC() {
System.out.println("The tourists are going to mountains ...");
}
public void doReturningTransport() {
System.out.println("The tourists are going home by air ...");
}}
iii. PackageB class
public class PackageB extends Trip {
public void doComingTransport() {
System.out.println("The tourists are comming by train ...");
}
public void doDayA() {
System.out.println("The tourists are visiting the mountain ...");
}
public void doDayB() {
System.out.println("The tourists are going to the olympic stadium ...");
}
public void doDayC() {
System.out.println("The tourists are going to zoo ...");
}
public void doReturningTransport() {
System.out.println("The tourists are going home by train ...");
}
}
Q: 5 Write intent and motivation of builder design

Motivation:

This type of design closely ties the object construction process with the components that make up the
object. This approach is well suited for the objects whose details are simple but with the increase in
complexity and number of components this approach is not suited merely due to maintenance issues.
This design may not be effective when the object being created is complex and the series of steps
constituting the object creation process can be implemented in different ways producing different
representations of the object.

Intent of Builder Design Pattern

i. Defines an instance for creating an object but letting subclasses decide which class to instantiate

4
ii. Refers to the newly created object through a common interface.

iii. Separate the construction of a complex object from its representation so that the same construction
process can create different representations.

Q: 6 in which situation factory design pattern should use

Factory method can be applied when:

i. A class can’t anticipate the class of object it must create.

ii. A class wants its subclass to specify the objects it creates.

iii. A class delegates the responsibility to one of its sub class for localization of object
instantiation.

Q: 7 Benefits of Iterator Design Pattern.

✓ Allows a client object to access the contents of a container in a sequential manner, without
having any knowledge about the internal representation of its contents.
✓ Client should not be involved in the internal traversal of the contents of the container.

Q: 8 Why should use prototype than other creational design patterns?

We should use prototype pattern due to some reason that are

✓ With the use of prototype pattern the objects can clone (copy) there is no need to create or
instantiate a new object.
✓ As the new object also take place in the memory. There is also need of new method that should
b apply on new object.
✓ But when we clone the object the basic method will be same of the object.
✓ So that the prototype can be use for memory saving. In other words can be use for reusability.
✓ It saves cost, time and resources

Q: 9 scenario of chocolate and asked about what pattern is used in this scenario. Write
simple code and optimized code.

Singleton Design Pattern will be use (Page No 207)

Q: 10 Draw sequence diagram of the scenario given above. Write your assumptions if any. In
doctor appointment system, there are multiple roles. To use the system the user logins in the
system as a patient (role) to make an appointment with the doctor. To make an appointment
he should enter medical specialty and date. Then system should look for the doctors available
for that specialty on that date. From the results patient should choose one and then system

5
save the appointment. At the end user should receive a confirmation email with the
information of the appointment including appointment schedule, doctor and location.

Doctor Appointment system

System Medical specialty Availability of


user Appointment
Interface and date doctor
Login()
Appointment request
for bone special list ()
Check availability()

available ()

Make a appountment()

Inform by email with Location date and time()

6
Q 11. Sequential diagram of a bank transition system? 10 marks

7
Q 12 A scenario is given for election and asks to make facade design pattern with
classes if multiple classes needed then made. If any other pattern is suggested then
use it.

Political election scenarios for local and international election, which allows the voter
registration with the restriction that only a voter can only give one vote, voter can also
change the vote as many times as he wants and many more lines.

We have to draw class diagram using façade. Then need to create a new one or
improved version of it by using any design pattern.

The voter will use the façade and façade will provide an interface to the system for the
online voting system.

Other pattern: the Singleton Design Pattern can also be used for this situation.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy