Results 1 to 2 of 2
Thread: classes, true purpose of
- 12-22-2009, 04:28 PM #1
classes, true purpose of
If variables store current state and methods implement behaviour and classes are basically a collections of methods grouped logically together ... i wonder how to better structure my classes content.
Say job is to take a look at 'n' files, read them into memory, do something and make a report - knowing that i will have to be reading more and more files in the future for other purposes, should i be placing method that actually reads a file and returns its contents into it's own utils.java class in my own com.mac.utils package so i can import it later into the main one?
In the industry, is this how things are done, or perhaps, you just make a local copy of that utils java and place it into the main package? To dwell more on this example a little bit - i don't know what type of return data my later code will need, so some overloading may be in order.
Am i thinking in the right direction? Please advise
Let me add that my current role in the organization has to do with supporting a large number of distributed applications. What this means is that master collection of tools is set to grow substantially over time. This means reusability is a must. And that begs the question, what should be reused? Should i concern myself with making a collection of reusable classes in my group's package com.group.utils?
Thanks for reading,
mac
- 12-22-2009, 05:34 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
You're halfway there; there is an important 'rule of thumb' that says 'code to the interface, not to the implementation'. To accomplish that task design interfaces first and try to make them 'fit' your use cases; just define what needs to be done, not how they should do it (of course you can keep that in the back of your mind but don't let it influence your interface design).
Next, if you're certain that implementations of those interfaces can do the job, implement the classes. If an interface A depends on an interface B make an implementation of A depend on interface B, not an implementation thereof.
Don't make your interfaces too general or you'll end up with implementations of that interface that can be best described as 'God classes' or 'Swiss Army knifes'. You don't want to maintain those molochs.
But first of all: practice and study because designing interfaces is something that swings you back and forth between generalizations for the sake of it to the need to get something implemented. Finding a balance between those two opposing forces is the thin line you have to walk.
kind regards,
Jos
Similar Threads
-
interface purpose?
By frejon26 in forum New To JavaReplies: 5Last Post: 06-27-2014, 10:41 AM -
while(true)
By ravian in forum New To JavaReplies: 7Last Post: 06-29-2011, 07:05 AM -
true && !true
By SirFalcon in forum New To JavaReplies: 3Last Post: 10-29-2009, 03:33 AM -
which one of the following is true about interface?
By makpandian in forum New To JavaReplies: 3Last Post: 06-30-2009, 01:23 AM -
Over-riding purpose fails..
By udayadas in forum New To JavaReplies: 7Last Post: 08-24-2008, 05:14 AM
Bookmarks