Quiz1 - Solution

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

MS Software Engineering, CS5151

Quiz 1 Solution

A parking lot or car park is a dedicated cleared area that is intended for parking vehicles.

We will focus on the following set of requirements while designing the parking lot:

1) Customers can collect a parking ticket from the entry points and can pay the parking fee at the
exit points on their way out.
2) Customers can pay the tickets via cash at the automated exit panel or to the parking attendant.
3) The system should not allow more vehicles than the maximum capacity of the parking lot. If the
parking is full, the system should be able to show a message at the entrance panel and on the
parking display board on the ground floor.
4) Parking will have many parking spots. The system should support multiple types of parking spots
such as Compact, Large, Handicapped, Motorcycle, etc.
5) The system should support parking for different types of vehicles like car, truck, van, motorcycle,
etc.
6) Parking should have a display board showing any free parking spot for each spot type.
7) The system should support a per-hour parking fee model. For example, customers have to pay
$4 for the hour.

A developer creates following class diagram of the above scenario. Identify and justify type of coupling
and cohesion in the given class diagram and python code.
class ParkingLot:
def __init__(self):
self.ticketList = []
self.largeSpots = 10
self.compactSpots = 10
self.handicappedSpots = 10
self.motorcycleSpots = 10

def GetNewParkingTicket(self):
ticket = ParkingTicket()
if ticket.AssignTicketToVehicle("Large", "Truck"):
ticket.ticketNumber = 123
ticket.issuedAt = "30-Sep"
ticket.spotNumber = 11
ticket.slotType = "Large"
ticket.vehicleType = "Truck"
self.largeSpots -= 1
ticket.PrintTicket()

class ParkingTicket:
def __init__(self):
self.ticketNumber = 0
self.issuedAt = ""
self.spotNumber = 0
self.slotType = ""
self.vehicleType = ""

def AssignTicketToVehicle(self, slotType, vehicleType):


if slotType == "Large" & vehicleType == "Truck":
return True

def PrintTicket(self):
print(self.ticketNumber)
print(self.issuedAt)
print(self.spotNumber)
print(self.slotType)
print(self.vehicleType)
Content Coupling
One class modifying internal information directly in this case Parking lot modifying information
of parking ticket in GetNewParkingTicket function.
Common Coupling
There is no common global data structure used in this case
External Coupling
No common global data variable used in this case
Control Coupling
Flags are passed here in function AssignTicketToVehicle based on which decision making is
performed so control coupling exists
Stamp Coupling
No common data structure is used
Data Coupling
Data coupling exists because data is passed in function AssignTicketToVehicle
Message Coupling
Message coupling exists because ParkingLot calling ParkingTicket functions
No Coupling
Coupling exists between two classes

Since Content Coupling exists which is the highest form of coupling therefore we can say that
there is very high coupling between these 2 classes
Coincidental Cohesion
No arbitrary grouping of functions found in these 2 classes
Logical Cohesion
The 2 functions AssignTicketToVehicle and PrintTicket of ParkingTicket are logically
grouped together otherwise there is no relation between the 2 functions
Temporal Cohesion
No temporal grouping of functions found in these 2 classes
Procedural Cohesion
No procedural grouping of functions found in these 2 classes
Communicational Cohesion
No grouping based on communication found in these 2 classes
Sequential Cohesion
No function grouping found based on sequence
Functional Cohesion
ParkingLot has functional cohesion but ParkingTicket does not have functional cohesion

Based on above the design has low cohesion.

You might also like