class - Is there a rule of thumb for how granular an object should be in OO programming? -


i'm in school learning oo programming, , next few months, every assignment involves dice games , word games jumble , hangman. each assignment has creating new class these variables; hangmanwordarray, jumblewordarray, etc. in interest of reusability, want create class (or series of classes) can re-used assignments. i'm having hard time visualizing like, , hope question makes sense...

let's assume class(es) contain properties accessors , mutators, , methods return various objects...a word, letter, die roll. there rule of thumb how organize these classes?

is best keep 1 object per class? or group objects in single class because they're related "stuff need assignments?" or group data type, numeric objects in 1 class , strings in another?

i guess i'm grappling how programmer, in real world, makes decisions how group objects within class or series of classes, , of questions , thought processes should using frame type of design scenario.

realistically, varies project project. there no guaranteed 'right way' group anything; depends on needs. comes down manageability, meaning how can read , update old code. if can contain games in single 'games' class, there's nothing wrong doing it. however, if games complicated many subs , variables, perhaps moving them own class easier manage.

that being said, there ways logically group items. instance if have lot of solo functions used manipulation (char string, string int, html encode/decode, etc.), may decide create 'helper functions' class hold them all. similarly, if application uses database connection, may create class hold , manage shared connection have methods getting query results , executing non-queries.

some people try break things down much. example, instead of having database core mentioned above, might create 1 class create , manage database connection. create class use connection class handle queries. not method won't work, may become difficult manage when items split small.

without knowing doing, there's no way tell how it. if reuse same methods in each project, perhaps can place them somewhere can shared. best way found figuring out works best try out , see how responds!


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -