I am developing a marketplace for real estate ads and I need some advice on which design pattern to use for creating different types of ads. Each ad can be either a Property or a Residence, and each Property has subclasses such as House, Flat, Garage, etc. Each subclass has its own fields and methods. Each Property also has a type of transaction, such as Buy, BuyNew, Rent, VacationRent, Colocation, etc. Each transaction type also has its own fields and methods. For example, Rent has duration and deposit fields, while VacationRent has rent fields plus vacation rent fields.
I want to know how to create an ad object that can handle different types of properties and transactions without using too many if-else statements or switch cases. I have read about some design patterns such as Strategy, State, Factory Method, etc., but I am not sure which one is the best for my problem. Can anyone suggest a good design pattern for this scenario. I am using PHP as my programming language.
I have searched online for similar problems but I could not find any clear solutions or examples.
Aucun commentaire:
Enregistrer un commentaire