Search code examples
javaoopobjectooad

Splitting objects into their most fundamental parts


Not sure if the title captures what I'm trying to say here.

When designing in OO should I be splitting my objects up into their most specific areas - so if I have a factory object that deals with creating objects but later on i come across a way of creating objects for another purpose even though they may be the same objects is it worth creating a seperate fcatory or just add to the exsiting.

My biggest worry is bulking up classes with tons of stuff, or splitting objects and diluting my projects into a sea of classes.

Any help?

EDIT:

I guess on a side note/sub topic part of me wants to find out the level of granularity you should use in a program. Kind of, how low should you go?


Solution

  • My biggest worry is bulking up classes with tons of stuff, or splitting objects and diluting my projects into a sea of classes

    This is a very valid point and in any even reasonably sized project, extremely difficult to get right up front especially because realistically, requirements themselves evolve over time in most cases. This is where "Refactoring" come in. You design based on what you know at any given point and try not too make too many leaps of faith as to what you think the system MAY evolve to.

    Given that you know what you are building right now, you design your classes trying to make the best possible use of OO concepts - eg encapsulation / polymorphism. This is itself, like others have noted as well, can be notoriously difficult to achieve and thats where experience, both in designing OO systems as well as knowledge of the domain can really come in handy.

    Design based on what you know --> Build It --> Review it --> Refactor it --> Re-design --> and it goes on and on..