OOP Gone Wild

Jun 14, 2016 22:24


In a piece of code I inherited from some smart, well meaning, but a little disorganized East European consultants, I found the following class hierarchy:

RestClient (abstract) JsonClient (abstract) XyzClient* SessionClient ApiClient

* XYZ is our proprietary service. The name was changed to protect the innocent.

It’s been ( Read more... )

software development

Leave a comment

Comments 22

dennisgorelik June 15 2016, 02:56:10 UTC
> Don’t do this at home

What exactly do you mean?

1) Do not use inheritance - use composition instead?
2) Do not use that many levels of inheritance?
3) Do not keep dead code?
4) Do not inherit concrete classes from concrete classes?

Reply

yatur June 15 2016, 02:59:42 UTC
Pretty much all of the above, with (1) corrected to "do not use implementation inheritance". I use it in tests for simplicity sometimes, but very rately in production code.

Reply

dennisgorelik June 15 2016, 03:06:29 UTC
What do you mean under "implementation inheritance"?

Is it when class inherits from interface?

Why not to use it? Occasionally it may be convenient.

Reply

yatur June 15 2016, 03:10:31 UTC
> Is it when class inherits from interface?

No. Google it.

Reply


dennisgorelik June 15 2016, 02:57:14 UTC
Did you delete all these classes from your codebase yet?

Reply

yatur June 15 2016, 03:09:24 UTC
No, I did not. I just discovered them today :)

The trouble is, current implementation is not standard compliant, and we need to fix it. But it is being actively used, so the old version must continue to function.

The project is not that big, so I am leaning towards leaving this project alone, creating a new one and pulling everything I need into it, on a strictly "as needed" basis.

I do not want to remove the code only to find later that it was actually used by some kind of stealth reflection mechanism I did not discover.

Reply

dennisgorelik June 15 2016, 03:44:48 UTC
> not standard compliant, and we need to fix it. But it is being actively used, so the old version must continue to function.

Do you mean that this inheritance hierarchy is standard compliant and is not in use?

> leaving this project alone, creating a new one and pulling everything I need into it

So you want to rewrite it from scratch?

Reply

yatur June 15 2016, 04:51:31 UTC
> Do you mean that this inheritance hierarchy is standard compliant and is not in use?

No. The software as a whole purports to implement certain protocol, but it is not standard compliant. The inheritance hierarchy appears to be dead code that plays no role in the (non)compliance.

> So you want to rewrite it from scratch?

Close, but not exactly. I am going to pull in existing useful pieces, but only those that are actually needed. I've done it before, Joel or no Joel :) The project size is small enough to make it manageable.

Reply


selfmade June 15 2016, 03:44:29 UTC
Make sure names of the classes are not referenced anywhere as plain strings for type instantiation, as well as any substrings like var protocol = "Xyz"; InstanceOf(protocol + "Client");
I've seen such tricks.

Reply

dennisgorelik June 15 2016, 03:47:24 UTC
If such instantiation code exists, it should be deleted too.

Reply

yatur June 15 2016, 04:48:15 UTC
Yep. I am going to start by writing a bunch of integration tests that ensure it does what it is supposed to do.

Reply


Leave a comment

Up