We recently had a code review . One of my classes was used so that I could return/pass more than one type of data from/to methods . The only methods that the class had were getters/setters . One of the team’s members ( whose opinion I respect ) said that having a class like that is bad practice ( and not very OOP ) . Why is that ?
Share
There’s an argument that classes should either be ‘data structures’ (i.e., focus on storing data with no functionality) or ‘functionality oriented’ (i.e., focus on performing certain actions while storing minimal state). If you follow that argument (which makes sense but isn’t always easy to do) then there is nothing necessarily wrong with that.
In fact, one would argue that beans and entity beans are essentially that – data containers with getters and setters.
I have seen certain sources (e.g., the book ‘clean code’) arguing that one should avoid methods with multiple parameters and instead pass them as a single object with getters and setters. This is also closer to the ‘smalltalk model’ of named parameters where order does not matter.
So I think that when used appropriately, your design makes sense.