dimanche 11 juin 2023

How should I design a new function according to OOP?

Say I need to add some function foo that takes an instance of type A and produces an instance of type B (assuming A and B are interfaces). In object-oriented design, what are the design limitations of either of the following designs?

Design 1:

class A {
  foo(): B { /* … */ }
}

Design 2:

class B {
  static foo(a: A): B { /* … */ }
}

Aucun commentaire:

Enregistrer un commentaire