K
K
Kolya Vantukh2020-05-13 19:08:08
PHP
Kolya Vantukh, 2020-05-13 19:08:08

How to apply polymorphism correctly?

Let's say in the system there is such an entity as the waybill (tn) for each of the delivery services. But depending on the type of tn, some can be edited in the database, others interact with third-party services (sdek) and they have the appropriate logic. How can I better build an architecture so that, for example, when editing an order, call the necessary tn methods depending on its type? (if ttn can be edited - edit, if you need to edit on a third-party service - do it) Make the appropriate interfaces for each type? ( EditableInDb, DeliveryServiceSyncetc.) and then check for the interface

if ($ttn instanceof EditableInDb) { 
//some logic
}

Which, for me, is not very good, because the differences in logic can grow in the future and there will be a lot of such checks for interfaces.
Or make a common interface for all types of tn and leave some methods without implementation for types of tn for which such behavior is not provided?
What do you say? Maybe there is a third option?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kolya Vantukh, 2020-05-14
@vkolya

Made a boolean type property, which will be the main main difference

A
Anton Shamanov, 2020-05-13
@SilenceOfWinter

implement strategy + decorator pattern

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question