java extend or wrap a class to add extra functionality
collections, java, list, pagination, wrapper
Solution
- in your case wrap the existing `List` and make your class implement `List` itself, delegating all methods the the original list (which is passed in constructor, for example)
- inheritance isn't always wrong, but in this case you won't know what class to extend - will it be `ArrayList`, or `LinkedList` ?
Problem
When you want to add some extra information into a class, what way would you prefer: would you extend that class or make a wrapper around it? In my particular scenario, I want to add some pagination information with a `List` that I get from database. That pagination information will include: ``` int currentPage; int totalResults; int containedResultsIndex; int totalcontainedResults; ``` and a couple of methods: ``` Boolean isNextPageAvailable(); Boolean isPrevPageAvailable(); ``` Whats your opinion, extend or wrap?