vendredi 24 novembre 2023

handle methods in a class calling shared sub-methods with varying order and frequency in Java/Kotlin

How can I implement multiple methods in a Java/Kotlin class that invoke the same sub-methods but in a different order, or sometimes a method calls more sub-methods than another? Is there a design pattern for this scenario?

                  +------------------+
                  |   My Class       |
                  +------------------+
                           |
            +--------------+--------------+
            |                             |
 +------------------+         +------------------+
 | Method A         |         | Method B         |
 +------------------+         +------------------+
 | Call SubMethod 1 |         | Call SubMethod 2 |
 | Call SubMethod 2 |         | Call SubMethod 1 |
 | ...              |         | ...              |
 +------------------+         +------------------+
                

  +------------------+         +------------------+
  | SubMethod 1      |         | SubMethod 2      |
  +------------------+         +------------------+
  | Implementation   |         | Implementation   |
  | ...              |         | ...              |
  +------------------+         +------------------+

but i have a lot number of methods to implement on the same class.

Aucun commentaire:

Enregistrer un commentaire