Best object-oriented way to solve the problem

1

Suppose I'm modeling a contracheque. However, each entry in a contracheque I chose to model as a ItemContracheque . That is, to represent my Contracheque as a whole, I can use a simple list of ItemContracheque .

Here is the question, if only a list of ItemContracheque can represent a whole contracheque, since it does not have any more attributes, I still need to create this contracheque object that would only have one attribute (a list of% %)?

What would be the most OO practice to adopt here? Do you create this object with only one Contracheque or represent a Contracheque using only a list of ItemContracheque ? And the main one, why choose one instead of the other?

This modeling will be used to return one of the webservice methods I'm doing.

With Java code to improve the issue:

public class Contracheque {
    private List<ItemContracheque> itensContracheque;
}

or just use:

List<ItemContracheque> itensContracheque;

That is, this would define the return of my method: either an object ItemContracheque or a Contracheque .

    
asked by anonymous 23.11.2016 / 18:53

1 answer

3

I do not think this has to do with OOP directly, it's just a form of modeling.

If you have an object that is a paycheck then you should have a type just to indicate it. Conceptually this is the correct one. And the items must be compounded within that object ( should not inherit anything, as I answered in a recent question ). It is the correct one for obvious reasons, so if the concept says that there is such an object, it must be created. It does not matter what's inside it, no matter the size.

Now saying that you only have the items should have a modeling error there. This is practically impossible. Of course, you can set it any way you want, but objects are not so simple. And as far as I know a paycheck, and I've worked with payroll, it's made up of several attributes. Does not the paycheck have a number? Competence? Whose is it? Total value, among other values?

    
23.11.2016 / 19:02