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?
bisect. verb. to divide something into two equal halves, especially in mathematics.
Central to object relations theory is the notion of splitting, which can be described as the mental separation of objects into "good" and "bad" parts and the subsequent repression of the "bad," or anxiety-provoking, aspects (Klein, 1932; 1935).
To characterize these cases Freud defined splitting of consciousness as a process of oscillation between two different psychical complexes, which become conscious and unconscious in alteration (Freud, 1912, p. 2850).
Examples of splitting behavior may include: Opportunities can either have "no risk" or be a "complete con" People can either be "evil" and "crooked" or "angels" and "perfect" Science, history, or news is either a "complete fact" or a "complete lie" Things are either "always" or "never"
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With