Stop being the product.
Become the owner.
or
sign uplog in

What’s the Best OOP Design for Sharing Behavior Across…

What’s the Best OOP Design for Sharing Behavior Across Only Some Derived Classes?

I’m trying to choose the right design approach/pattern for the following situation.

I have one base class that provides some common functionality, and several derived classes that use it. However, some behaviors are shared only by certain derived classes, not by all of them.

For example:

* Derived1 and Derived3 can move.
* Derived2 and Derived4 can shoot.
* Some future classes might be able to both move and shoot.
* Some might be static and do neither.

Because move() and shoot() are not common to all subclasses, I don’t think they belong in the base class. But I also don’t want to duplicate the same behavior in every derived class that needs it.

What would be the best way to design this?

Should I use composition, Strategy pattern, interfaces, or something else?

I’m looking for a scalable and clean OOP design, preferably following SOLID principles, where behavior can be reused without forcing every derived class to inherit methods it doesn’t need.

#dev #technology #programming
earnings
2,000 mlx total
$0  total
engagement
3 views
0 reactions

0 comments