Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I see this as an example of a meaningful abstraction. A good abstraction has a couple of traits:

  1. It hides implementation details which are irrelevant to the code consuming it.

  2. It is only as complex as it needs to be.

By extending, you're exposing the entire interface of the parent, but in many cases much of that may be better hidden, so you'd want to do what Sebastian Redl suggests and favor composition over inheritencefavor composition over inheritence and add an instance of the parent as a private member of your custom class. Any of the interface methods that do make sense for your abstraction can be easily delegated to (in your case) the inner collection.

As for a performance impact, it's always a good idea to optimize code for readability first, and if a performance impact is suspected, profile the code to compare the two implementations.

I see this as an example of a meaningful abstraction. A good abstraction has a couple of traits:

  1. It hides implementation details which are irrelevant to the code consuming it.

  2. It is only as complex as it needs to be.

By extending, you're exposing the entire interface of the parent, but in many cases much of that may be better hidden, so you'd want to do what Sebastian Redl suggests and favor composition over inheritence and add an instance of the parent as a private member of your custom class. Any of the interface methods that do make sense for your abstraction can be easily delegated to (in your case) the inner collection.

As for a performance impact, it's always a good idea to optimize code for readability first, and if a performance impact is suspected, profile the code to compare the two implementations.

I see this as an example of a meaningful abstraction. A good abstraction has a couple of traits:

  1. It hides implementation details which are irrelevant to the code consuming it.

  2. It is only as complex as it needs to be.

By extending, you're exposing the entire interface of the parent, but in many cases much of that may be better hidden, so you'd want to do what Sebastian Redl suggests and favor composition over inheritence and add an instance of the parent as a private member of your custom class. Any of the interface methods that do make sense for your abstraction can be easily delegated to (in your case) the inner collection.

As for a performance impact, it's always a good idea to optimize code for readability first, and if a performance impact is suspected, profile the code to compare the two implementations.

Source Link
Mike Partridge
  • 6.7k
  • 1
  • 26
  • 40

I see this as an example of a meaningful abstraction. A good abstraction has a couple of traits:

  1. It hides implementation details which are irrelevant to the code consuming it.

  2. It is only as complex as it needs to be.

By extending, you're exposing the entire interface of the parent, but in many cases much of that may be better hidden, so you'd want to do what Sebastian Redl suggests and favor composition over inheritence and add an instance of the parent as a private member of your custom class. Any of the interface methods that do make sense for your abstraction can be easily delegated to (in your case) the inner collection.

As for a performance impact, it's always a good idea to optimize code for readability first, and if a performance impact is suspected, profile the code to compare the two implementations.