Click here to Skip to main content
16,011,436 members
Home / Discussions / Java
   

Java

 
GeneralRe: How do I decide for class responsibilities? Pin
Nagy Vilmos9-Jul-12 8:48
professionalNagy Vilmos9-Jul-12 8:48 
GeneralRe: How do I decide for class responsibilities? Pin
Richard MacCutchan9-Jul-12 9:03
mveRichard MacCutchan9-Jul-12 9:03 
GeneralRe: How do I decide for class responsibilities? Pin
Nagy Vilmos9-Jul-12 9:12
professionalNagy Vilmos9-Jul-12 9:12 
GeneralRe: How do I decide for class responsibilities? Pin
jschell9-Jul-12 12:13
jschell9-Jul-12 12:13 
GeneralRe: How do I decide for class responsibilities? Pin
pasztorpisti14-Jul-12 0:03
pasztorpisti14-Jul-12 0:03 
GeneralRe: How do I decide for class responsibilities? Pin
jschell9-Jul-12 12:01
jschell9-Jul-12 12:01 
GeneralRe: How do I decide for class responsibilities? Pin
Andrei Straut16-Jul-12 0:22
Andrei Straut16-Jul-12 0:22 
GeneralRe: How do I decide for class responsibilities? Pin
pasztorpisti13-Jul-12 23:40
pasztorpisti13-Jul-12 23:40 
This is code design not a grammar lesson! XD But for some extent your statement is true because some of the nouns usually identify your packages or classes or the data structures you might pack into a single class. Don't rely on methods, use your brain and experience. There is no method that compensates you for not having experience so practice! practice! practice! But on my road learning code design I use the following guidline:

First you have to be able to break down a problem into small pieces, then to break down those pieces into even smaller pieces. This is the most difficult step, you need some coding experience to do this. You have to be able to identify problems and patterns. This way you get a "hierarchy of problems" a "tree of those problems". The root of this tree is your program, some nodes in the tree below the root are packages, and as you go down towards the leaf nodes you will find classes sooner or later. If you break down the problems with enough granulartiy your tree will identify the package and class structure of your program too. Of course you can start this tree from a package or class level if you have to solve only a part of the problems.
Now you have the classes and you have to find out what kind of data, which member variables are needed to solve the problems that belong to a class and you have to put them into the right class, the same is true for the methods that work with that data.

I usually spot out bad code design in a minute, this usually involves code (method(s)) that doesn't work with the member variables of the actual class the method resides in, instead the method uses data and methods that it reaches from other objects. In this case the method should be moved to somewhere else where its most used data resides. If it uses a lot of data from here and there maybe from incoming parameters (or a lot of classes call that method) then it can be put into a helper class as a static helper method.
EDIT: Another bad design is bloat code - huge monolithic classes. In this case the problem the class solves needs to be split into sub-problems and more classes.

modified 14-Jul-12 5:53am.

AnswerRe: How do I decide for class responsibilities? Pin
Pete O'Hanlon9-Jul-12 7:55
mvePete O'Hanlon9-Jul-12 7:55 
GeneralRe: How do I decide for class responsibilities? Pin
Nagy Vilmos9-Jul-12 8:23
professionalNagy Vilmos9-Jul-12 8:23 
GeneralRe: How do I decide for class responsibilities? Pin
Pete O'Hanlon9-Jul-12 8:31
mvePete O'Hanlon9-Jul-12 8:31 
GeneralRe: How do I decide for class responsibilities? Pin
Nagy Vilmos9-Jul-12 8:33
professionalNagy Vilmos9-Jul-12 8:33 
GeneralRe: How do I decide for class responsibilities? Pin
Pete O'Hanlon9-Jul-12 8:41
mvePete O'Hanlon9-Jul-12 8:41 
GeneralRe: How do I decide for class responsibilities? Pin
Nagy Vilmos9-Jul-12 8:45
professionalNagy Vilmos9-Jul-12 8:45 
GeneralRe: How do I decide for class responsibilities? Pin
Pete O'Hanlon9-Jul-12 8:53
mvePete O'Hanlon9-Jul-12 8:53 
GeneralRe: How do I decide for class responsibilities? Pin
Nagy Vilmos9-Jul-12 9:00
professionalNagy Vilmos9-Jul-12 9:00 
AnswerRe: How do I decide for class responsibilities? Pin
Stingrae7899-Jul-12 10:00
Stingrae7899-Jul-12 10:00 
QuestionInstrument Automation Pin
CMA215-Jul-12 10:45
CMA215-Jul-12 10:45 
AnswerRe: Instrument Automation Pin
TorstenH.5-Jul-12 19:22
TorstenH.5-Jul-12 19:22 
AnswerRe: Instrument Automation Pin
jschell6-Jul-12 11:20
jschell6-Jul-12 11:20 
Questionjava with text file Pin
RORY175-Jul-12 9:35
RORY175-Jul-12 9:35 
AnswerRe: java with text file Pin
TorstenH.5-Jul-12 19:13
TorstenH.5-Jul-12 19:13 
GeneralRe: java with text file Pin
RORY175-Jul-12 23:15
RORY175-Jul-12 23:15 
GeneralRe: java with text file Pin
RORY175-Jul-12 23:37
RORY175-Jul-12 23:37 
GeneralRe: java with text file Pin
TorstenH.5-Jul-12 23:40
TorstenH.5-Jul-12 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.