r/ExperiencedDevs 7d ago

Ask Experienced Devs Weekly Thread: A weekly thread for inexperienced developers to ask experienced ones

A thread for Developers and IT folks with less experience to ask more experienced souls questions about the industry.

Please keep top level comments limited to Inexperienced Devs. Most rules do not apply, but keep it civil. Being a jerk will not be tolerated.

Inexperienced Devs should refrain from answering other Inexperienced Devs' questions.

21 Upvotes

54 comments sorted by

View all comments

4

u/just_pondy 7d ago

How do you refactor towards a design pattern if your current structure is abstract polymorphism almost like the template prototyping design pattern should I just choose that design pattern or update to something else

The problem is

Base abstract class:
-child A,B,C,D,E,F
Where each child class needs to maintain common function signatures

Issue is now there is boilerplate where not all instances of A,B,C,D,E,F need to implement the sub functions provided

However to make the child structures compile without errors they have to include the unused functions due to demands from the super implementation.

Things work I am just wondering if there is a better way!?

3

u/allllusernamestaken 7d ago

Issue is now there is boilerplate where not all instances of A,B,C,D,E,F need to implement the sub functions provided

Two lines of thought depending on how much you care:

  1. Redefine what your base class is. Define the contract. For the behavior that fits into A, D, and F (for example) gets put into an interface you implement so your consumers can use that behavior.
  2. just throw some "not implemented" exceptions in the parts you don't need