aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Data Class Doing Too Much? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Data Class Doing Too Much?" Watch "Data Class Doing Too Much?" New topic
Author

Data Class Doing Too Much?

Daniel Simpson
Ranch Hand

Joined: Sep 02, 2004
Posts: 181
I'm beginning to wonder if my Data class is doing too much. It implements all of the methods from the DB interface and performs all of the reading and writing of the database file and the cache. I do have a DBDataAdapter class but that controls the booking method for the client. Has anybody else used just the Data class to do all of this, and passed the exam? Just curious.


SCJP 1.4<br />SCJD 1.4
Barend Garvelink
Ranch Hand

Joined: Dec 07, 2004
Posts: 64
One of the principles of object oriented design is to have a single responsiblity per class file, where possible. This helps promote object re-use. One other thing to consider is that breaking up large files might make your sourcecode easier to read.

I haven't submitted my own assignment yet, and I don't know what your sourcefile looks like. However, with the above in mind I suggest you see if you can find a sensible way to divide resposibilities over a number of classes.


SCJP 1.4, SCJD 1.4, SCWCD 1.3, ICSD:Websphere 5.1
Daniel Simpson
Ranch Hand

Joined: Sep 02, 2004
Posts: 181
Originally posted by Barend Garvelink:
One of the principles of object oriented design is to have a single responsiblity per class file, where possible. This helps promote object re-use. One other thing to consider is that breaking up large files might make your sourcecode easier to read.

I haven't submitted my own assignment yet, and I don't know what your sourcefile looks like. However, with the above in mind I suggest you see if you can find a sensible way to divide resposibilities over a number of classes.


My Data class is roughly around 650-700 lines of code for all of the DB interface methods that I implemented (including comments, class variables). I also have methods to read in the schema, cache records, test record validity by reading the cache. Is this wrong? Or should I think about having a class that only reads the schema. A class that Caches records? What do you think?
[ December 07, 2004: Message edited by: Daniel Simpson ]
Barend Garvelink
Ranch Hand

Joined: Dec 07, 2004
Posts: 64
Originally posted by Daniel Simpson:


My Data class is roughly around 650-700 lines of code for all of the DB interface methods that I implemented (including comments, class variables). I also have methods to read in the schema, cache records, test record validity by reading the cache. Is this wrong? Or should I think about having a class that only reads the schema. A class that Caches records? What do you think?


Should I read that as 650-700 for the entire source file, or "650-700 for the DB interface methods" (and some more for everything else)?

It's not "wrong" per se, but if the file is overly long you might lose some points in in the categories code clarity and OO design, which would be a shame. That's not for me to judge. In my opinion it would be safer to split up the class, e.g. into seperate classes for MetaData, Record, Validation, LockManager, CacheManager -- but the decisions are up to you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data Class Doing Too Much?