samedi 14 décembre 2019

Confused about applying Design Patterns

I am designing a system for Airport as a part of office project and I am supposed to design a class for handling passengers. I am using WPF MVVM so I have my PassengerInfoViewModel which basically represents a Passenger travelling to Airport. I am confused among using State,Visitor and Decorator patterns.

The requirement is as below :-

1) There are several types of Passengers. Passenger can be a Passenger with SSN + verified biometrics, SSN + enrolled without verified biometrics, Without SSN + enrolled without verified biometrics, With SSN + enrolled without verified biometrics and other combinations with some other entities.

2) Any of the above passenger can have one of the following status. NewEnrollment, WaitingForVerification, Verified, Rejected, Deboarded, Cancelled etc. The status of the passenger is updated based on some actions performed by airport staff. But this will be updated not during a single transaction. The updated status will be pulled next time a passenger inputs the Booking Reference number.

3) A passenger can opt for special assistance that triggers a special workflow. The passenger can check/uncheck special assistance during a single transaction. So, the values keep updating in a single transaction. Once the transaction is over, and if the passenger has opted for Special assistance, this can't be changed again.

What I am planning to do is :-

1) Create a base abstract Passenger class which has basic demographic and other details common across all the passengers. PassengerWithSSN and PassengerWithoutSSN can be a seperate class with a VerificatonStatus field Verified,EnrolledPendingVerification etc. This will be fetched when initial transaction begins.

Is this right or should I make seperate classes for each type (I am thinking so). Reason being each type triggers a different workflow. As the state does not change during a transaction, I am not going with State pattern.

Also, I should be able to plug different workflows per type in future. Workflows involve calling separate APIs and navigation to different pages. Experts please suggest.

2) For NewEnrollment,WaitingForVerification etc, this will be put into a PaxStatus and I am planning to use Visitor pattern to handle the logic for this, keeping it out of the main class. Not sure if this is the right approach.

3) The SpecialAssistance is something which will change during transaction so I am planning to use State design pattern here. SpecialAssistance state and NormalPassengerState. Also there might be an Infant state in case parents want to register Infants for workflows.

There are N*N combinations (e.g. a Non-Verified passenger with Biometrics Enrolled and has SSN travelling with an Infant and needing special assistance) which might mess up needing a lot of rework in future if not designed properly.

Can anyone guide me in the right direction?

Aucun commentaire:

Enregistrer un commentaire