question archive Q4

Q4

Subject:Computer SciencePrice: Bought3

Q4. There are range of design patterns - creational, structural and behavioral pattern types. Analyze given scenarios(a) to (d) and identify the most appropriate design pattern from a range.

a)   You are a member of a programming team, and have been asked to design the class structure for a custom aircraft design system in a computer game. An aircraft will have two basic properties: its name and capacity. Each aircraft can then be customised with various additions. An aircraft may optionally have one or all of a first-class cabin, a viewing area, a communications system and/or a booster rocket. A first-class cabin means the aircraft can have first-class passengers, a viewing area is a place where passengers can watch the scenery below, a communications system is so passengers can talk to people on the ground, and a booster rocket enables the aircraft to move twice as fast. For example, the aircraft GoodCruiser has a capacity of 100 passengers, a first-class cabin and a booster rocket. The aircraft RuthlessRogue has a capacity of 20 passengers, a viewing area and a communications system.

One member of your team quickly begins outlining a set of classes on the whiteboard:

// The generic aircraft

class Aircraft { private int capacity; private String name; }

// An aircraft with an added first-class cabin

class FirstClassCabinAircraft extends Aircraft { }

// An aircraft with an added viewing area

class ViewingAreaAircraft extends Aircraft { }

// An aircraft with an added communications system

class CommunicationsSystemAircraft extends Aircraft { }

// An aircraft with an added first-class cabin and communications system class FirstClassCabinCommunicationsSystemAircraft extends Aircraft { }

What is wrong with the design? Which design pattern would be suitable to remove deficiencies in the design.

 

b)   Consider a scenario of a database server. We want to efficiently manage and restrict the number of connections to databases. Which design pattern would be suitable in this case?

c)   Consider a scenario of database transactions. There are different types of database transactions, e.g. add record, update record and delete record etc. If transaction fails, then there is an option of rollback transaction. Which design pattern is suitable to handle these types of transactions and also provides the ability to encapsulate these processes?

d)   Consider a scenario of house building. There are two options to build house i.e. Wooden House and Glass House. However, the processes / steps for building any two of them are same which include operations such as build foundation, build pillars, build walls and build windows etc. Although, the processes / steps are same but implementation is different for wooden and glass houses. Which design pattern would be suitable to implement this scenario?

 

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions