0

I created a DataThread class that doesn't extend a Thread, but has one as a member variable.

Favor composition over inheritance, is a rule that I heard of, but I am thinking that the name of the class should be change, as to not mislead.

Is this true?

1 Answer 1

1

It's not true.

The name of a class is part of its public interface. The user of a public interface doesn't care how functionality is implemented, only that it is available. (Indeed, allowing the user to not care about the implementation is the entire point of writing a class.)

Therefore, as long as the class offers the kind of operation commonly present in a Thread class, it doesn't matter whether internally this is done via delegation or inheritance. If your class is a drop-in replacement for a thread, by all means call it a name with "thread" in it.

1
  • what if it is not a proper replacement for a thread, but just uses part of the functionality?
    – user85190
    Commented Jul 23, 2015 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.