Reuse is good!

One of the theme that I’ve always seen in design when people try to create some kind of “framework” is the heavily use of inheritance. Because one of the thing that people has been taught is “reuse is good”. Looks at the design below (noted that this design has nothing to do with DDD)

The same design is applied for repositories…

And the only reason to have this kind of design is for reusability, no infrastructure codes can easily deal with IService<T> or any other base classes in this design. (And there is no reason for infrastructure codes to deal with those things)

The next question is what happens if the UserService (or any service class) doesn’t need all functions implemented in the base class? What happens if there are some business rules need to be checked? (Then the workaround is to add more abstract methods around all functions in the base class)

The point here is: There is no reason to create a complex but not very useful design. My preferable design is something likes

We can still reuse some of the codes through composition but not inheritance, there is a well written blog post discuss almost the same issue here


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s