Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Efficiency and OO design what is best?

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
Take these situations what is best? And why?

1) Have a large class with all the methods in it that act as utility methods to the class. What I mean is that I have many data structures in this one class and I need to do things with them to create more so the methods in the class use these data structures.

2) Or is it better to have a class with static methods that take these data structures and return other data structures essentially having the same effect as option 1.

3) Or is it better to have these methods as classes which take data structures in the constructor and then return other data structures.

This is a kind of OO question and be grateful for any responses especially in OO rightness(if there is such a thing ) and especially with respect with efficieny. I have a feeling that having all the methods in one class is more efficient ( something to do with memmory)

Cheers.

Chris
 
The balance of efficiency and correctness (in the context of OO) is an interesting one. I teach Java and OO to degree students and come across code which is so OO that it's very inefficient. When designing a program, the efficienty of the design (or rather the resulting implementation needs some though. Remember however that the more method calls you make, the more inefficient the program is! The answer to your question IMHO is about balance.
 
djabell, would you say that the best approach is to produce a logical OO design first and physicalise it after? This would be similar to database design methodologies.

When programmers dive straight into a 'tuned' design I worry about OO concepts being missed. My home ----> visit me for Java and Data Warehousing resources
 
From an OO perspective, I recommend reading or looking through 'Design Patterns - Elements of Reusable Object-Oriented Software' by Gamma, Helm, Johnson and Vlissides (The Gang of Four). The requirements you put are discussed as Creational Patterns, and go through the merits and demerits of the choices available. Look also at which is a useful resource for understanding some pattern structures.

With respect to efficiency, the choices you make are dependent on sound analysis and requirement. As a general rule, I would suggest that making efficiency modifications (outside of the normal efficient coding practices) should only be done when it has been identified that there is a performance problem and the source of the problem is known. David Mellors
First Light Associates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top