• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

[ OO purist vs practicalities ]

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you are designing an OO application, do people design with the intention of minimizing the number of classes created ? In java, one can get carried away and create numerous itty bitty classes.
I am in the middle of a discussion with a colleague who is in favor of designing a class X that will provide all behavior versus my design which is some an abstract class A, realized by user defined classes as they see fit.
To me, coming out with a mother-of-all class X is going to be difficult to maintain, as developers will continue to add on extra functionality and we end up with one blotted class.
But my colleague countered that having to load those itty bitty classes would mean slower performance as class instantiation is a slow process.
What are your thoughts ?
Pho
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally I think your colleague is dwelling too much on the thought that the number of objects in a design has some meaningful relationship with how well the system performs. You went with an Object-Oriented Platform for a reason: to utilize Object-Oriented features. If immediately limit the number of classes that you are allowing yourself to create then you are handicaping yourself from the start.
The truth is that you don't where the performance bottleneck of your system is going to be. You haven't even designed the system so how could you know? Experience tells us that the bottleneck is almost always not in the place that you initially expect.
First and foremost you should design your system in a well-factored manner and don't be overly concerned with performance. Near the end of your project do some profiling and then target the specific areas of the system that are causing performance issues. You will gain much more from targeting these specific areas for performance then by constantly optimizing everything that you write and your code will still remain manageable.
Nobody gets the design right the first time either, so refactor constantly. Refactoring is one of the best tools that any developer has. Use it.
BTW, ignore all of this if you are writing a real-time system.
[ September 19, 2002: Message edited by: Chris Mathews ]
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see I've beat Ilja to it, but here's the first rule of optimization:
Don't.
(once in a while you have to consult the second rule though)
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Mathews:

First and foremost you should design your system in a well-factored manner and don't be overly concerned with performance. Near the end of your project do some profiling and then target the specific areas of the system that are causing performance issues. You will gain much more from targeting these specific areas for performance then by constantly optimizing everything that you write and your code will still remain manageable.


Fully agreed. Additionally, having a design conforming to the Single Responsibility Principle will make finding and fixing a bottleneck much more easy.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Weitzman:
I see I've beat Ilja to it, but here's the first rule of optimization:
Don't.


Damned! Now, what's left to do for me?
 
Marshal
Posts: 16591
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
Damned! Now, what's left to do for me?
Well, David gave you a chance to go for the second rule... but you blew that, too!
Second Rule of Optimization (for experts only):
Don't Yet
[ September 19, 2002: Message edited by: Junilu Lacar ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Junilu Lacar:
Well, David gave you a chance to go for the second rule... but you blew that, too!


At least you gave me the chance to go for the third...
Third Rule Of Optimization: (if you really, really have to) Use a profiler to find the bottleneck - it isn't were you think it is.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See also http://c2.com/cgi/wiki?FearOfAddingClasses
 
this is supposed to be a surprise, but it smells like a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic