Pharmacy sells medicine from different producers. Each medicine has a name, type (antibiotics, anti-inflammatory, stomach), price etc. However, imported medicine must have a certificate from a lab in the current country. Moreover, if customer purchases an imported medicine, the pharmacy worker has got to query the medicine database and see the data about the counterpart medicine from domestic producers (which are usually cheaper).
How do we develop a class structure to handle medicine data in this pharmacy?
I found Applying UML and Patterns by Craig Larman a very good book to learn about design, patterns and implementation.
If you want a quicker solution rather than reading an entire book, just prototype something: Create some classes, figure out what your interface will be etc. Try some stuff out to see what would be easiest to implement/maintain.
A possibility:
You have a
ProductService
which has aFindCounterpartMedicines()
. If the case described in your question is the only special case, it can be achieved with just a simpleif
: Don't complicate things if it is not necessary but "Do the simplest thing that could possibly work" (link).If each medicine has some different special logic, you can use polymorphism to avoid a list of
Inheritance example