I have a class called Page in my program. It has 10 attributes, but at certain point, only 3 attributes are needed (RawPage) and in other point, all or almost all atributes are needed (ProcessedPage).
Is better I have only only one class with all attributes or split these class into two classes, one for every need?
EDIT: the processed atributes are new attributes in the Page, and not overwrites none.
I suspect someone will suggest using inheritance here, but I won’t… it sounds like you logically create a “processed page” from a “raw page” (via processing) – so why not model it exactly like that?
When a class has information which is only sometimes valid / needed / relevant, it ends up being quite tricky to work with, especially as the system grows in size. With a more explicit model, you do potentially end up with some duplication, but your classes end up with a better defined purpose in life, rather than suffering from multiple personality disorder.
Note that I haven’t made
ProcessedPagea subclass ofRawPage– because I don’t imagine you’d normally want to treat aProcessedPageas aRawPage, potentially reprocessing it. You may want to have a common interface that they both implement which doesn’t include theprocessmethod, of course, but that’s slightly different.