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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Take these situations what is best? And why?

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
 
Chris

I personally would go for number 1. I think one of the most important things is to make sure your code in the class is readable. Also make sure when the class is simple to implement. If you go for number 2 or 3 implementation would be complicated and hard to follow.

As long as you document your class well number one should not be a problem.

I would also be interested in yours and other peoples views on this subject.

Good luck
 
Thanks for your reply. I have posted this message in a few forums and it seems there isn't a strict OO convention or rational.

I choose 1 as well. 3 I think is the worst approach.

But I don't have a specific irrefutable rational for this.

I basically just thought that a class should have one particular function and that passing large data structures about was poor OO design. Something to do with something I read about coupling and cohesion.

The class is approximately 2500 lines long.

I guess you had other reasons for choosing number 1?

Chris
 
I don't fully understand your solution levels.

OO rightness. Love it... Prefer OO completeness instead.

With that in mind, the questions become where do you stray from the path and is it Okay?

Your attempt to view the solution as a "single class" was your downfall.

A data structure is a class. It's simply a class with no methods and a pile of public properties. This blows your single class concept to poof. Encapsulation or protection of the data is the most fundamental OO concept. By ignoring this fact you deluded yourself into thinking your single class concept was safe. This basic failure leads you to further transgression.

Many static methods or dynamic methods with "data structures" passed... There are better ways to achieve polymorphism! Embrace the fact that the data structures as you call them are classes, they CAN have methods. They CAN be derrived from a common ancestor. Thru this ancestor common properties and methods can be defined and inherited. Virtual methods fill in gaps where a methods with varying implementations exist.

Now the bottom line. Sure you went off the OO path. Is your code portable, understandable, and easily maintained? If so, your transgression is forgiven.... this time.




Wil Mead
wmead@optonline.net

 
I would go with method 1, mainly because if you write the code nice and clean, you can least make sure that every part is encapsulated alone, and not spread all over the place. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Thank you kb244,

Will mead, I do not understand most of what you are saying. I cannot see how a data structure is a class. By data structure I just meant an array.

Moreover I have not tried to achieve polymorphism as polymorphism would not have helped me to achieve my goal.

As you have pointed out my definitions of simple terms such as a class differ greatly from yours and mine are wrong. So given this information I don't quite understand your rational for including so many new technical terms 'knowing' that I have poor definitions of the basic terms.

Furthermore, the tone of your reply seems quite condescending, but fully understand this may not have been your intentions and could be my misinterpretation.

Having said this, I am also fully aware that your answers could be the most correct answers. And I would be greatful if you could reply with a spefic answer to the original question. Moreover, I would be greatful if you try to explain with less technical words or explain what these technical words means.

Thanks

Chris

PS excuse my poor english.

 
Chris

You could look into the subject of patterns in an attempt to answer your question. One pattern in particular is the 'facade' pattern which would be a good answer to your question.

If you havent seen patterns before they are simply a way of organising classes. They are used through out industry and make the design process of object orientated systems much easier.

I havent loooked on the internet but im sure many tutorials exist. If I come accross one then I will post its address on this site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top