CS711 Final Term Paper (Naina Malik)
CS711 Final Term Paper (Naina Malik)
✓ 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.
✓ Array is declared to store a certain number of a certain kind of variables. (page no 280)
✓ 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.
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.
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.
iii. A class delegates the responsibility to one of its sub class for localization of object
instantiation.
✓ 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.
✓ 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.
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.
available ()
Make a appountment()
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.