473,883 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When not to use Object Oriented Programming?

Curtis Rutland
3,256 Recognized Expert Specialist
I was reading through some job postings on a game developer's web site (without any real interest of applying). One of the ones that I saw had this bullet point in the requirements:
  • Appreciation of when not to use Object Oriented Programming.
I've done almost all my work in OO languages...so can someone enlighten me? When do you not want to use OOP?
Dec 23 '08
41 18867
8 New Member
lol, yes many years programming in C++ and Java, and recently a little dabbling in PHP, the latter versions of which have some OO support.

Don't get me wrong, I didn't mean to come off sounding anti-OO. But I have seen it taken to what I consider to be illogical conclusions. In the example I posted about above, the OO extremists would want to extend the java.util.List class to include a method that would total the contents of the List (very much an OO principle). And while this might sound like a good idea, what it would mean is that after iterating through the List of objects to render them in the report, it would then be iterating through the List again to do the total when you invoke the method at the end. So then you'd be looping through the List twice instead of just once.

No big deal for small Lists, in small apps., with few users. But as you scale this up, you will definitely see problems. Multiply that inefficiency out times millions of concurrent users, with larger data sets, and you will see unacceptable response times, and a grumpy JVM which might run out of heap space. (Ask me how I know...)

This example exaggerates to make a point - but I've seen that pattern of thinking pervade the OO community. It's just something that you have to keep an eye on.

Jun 12 '09 #21
32,584 Recognized Expert Moderator MVP
Personally, I come from a position of not being a great OO expert at all.

I have just learned from long experience that as soon as someone draws conclusions from a perceived flaw in the design, someone else pops up to explain why the problem is restricted to a particular approach and not the concept as a whole. It just takes a different way of thinking to perceive the better approach (or someone telling you of course :D).

This is life experience more than OO specifically of course, but I've seen it so often in relation to OO that I just felt the need to interject.

As far as taking things to their logical conclusions in the absence of common sense is concerned, I agree that's a bad idea. It's just that sometimes it's difficult to determine when this is hapenning. There are always ideas we may not be aware of waiting to expand our horizons.

Welcome to Bytes!
Jun 12 '09 #22
5,058 Recognized Expert Expert
Or, rather then count the list when the total method is called, create a private variable and modify that as each list item is added/removed.
Then return that value when the total method is called.

I realize this was perhaps just an example to make a point, but I just wanted to demonstrate the there is usually a way around these sort of situations.
Jun 12 '09 #23
8 New Member
... the problem is restricted to a particular approach and not the concept as a whole.
Nicely stated, and absolutely true.

Or, rather then count the list when the total method is called, create a private variable and modify that as each list item is added/removed.
Then return that value when the total method is called.
This is not bad, but it suffers from the possibility that in many cases, even for the same List of objects, you may not need the total. But you're adding globally to the cost of inserting/deleting/updating objects in the List. It's still cheaper to just tally the total only when needed, and on the fly when you are iterating through the list already for some other reason.

* * *

The OP just wanted to know when not to use OOP, and the answer of course is a big fat "it depends". But it does not surprise me at all to see a bullet like "Appreciati on of when not to use Object Oriented Programming." in a shop that produces games, flight sims., or highly scaled apps. I think what they're getting at there is not necessarily that they don't want you to use OOP at all, but just know when you are using an OOP principle in a way that is inefficient because it really matters in high performance software.

Welcome to Bytes!
Thank you!

Jun 12 '09 #24
11,448 Recognized Expert MVP
If you only anticipate for the possibility that every member of a list needs some form of processing then the following interface (Java) springs to mind:

Expand|Select|Wrap|Line Numbers
  1. public interface ElementProcessor<R, T {
  2.    public void process(T element);
  3.    public R result();
  4. }
Your original code just has to maintain a list of ElementProcesso rs and call them when a new element has arrived. It is a breeze to come up with a TotalProcessor without any overhead in processing time. This scenario allows for expansion of the idea when a customer wants to have, say, a standard deviation of all the numbers or whatever; there would be no need to fiddle diddle with the original code again: simply implement the interface shown above, feed it to your original code and voila.

kind regards,

Jun 12 '09 #25
11,448 Recognized Expert MVP
Yep, (also see my previous reply); good OO systems are very fast when it comes to memory allocation and the creation of just one object at the beginning doesn't take any noticable time. The 'solution' (mind the quotes) that John came up with in his story is just ludicrous; a bit of thinking might have shown why.

There is no (noticable) overhead in OO programs; it's just that people don't know how to use it efficiently but if they want Fortran they know where to find it.

kind regards
Jun 12 '09 #26
7,872 Recognized Expert Expert
fortran I believe is still one of the best at doing floating point math. That's surely not OOP
Jun 12 '09 #27
8 New Member
The 'solution' (mind the quotes) that John came up with in his story is just ludicrous; a bit of thinking might have shown why.
Ok, I have to ask: why is the 'solution' I came up with ludicrous?

Jun 12 '09 #28
5,058 Recognized Expert Expert
Because of the reasons you yourself gave us.
It's extremely wasteful to count the list every time the total() method would be called.
Jun 12 '09 #29
8 New Member
Even that depends. The same list of objects might be being used by another part of the system that does not need totals, so you don't want to be incrementing/decrementing a static total for the List every time an object is inserted/deleted/changed.

See what I mean? It just depends. Beyond simple and obvious algorithmic improvements, most decisions like that are a trade-off of some sort.

The other thing you need to consider is what developers are likely to be supporting/maintaining the codebase once you are gone. That's another discussion, but it may be related to what the OP was inquiring about, and may also be the motivation for the bullet in the job posting by the game company.

Jun 12 '09 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Pmb | last post by:
Hi. I'm new to this group. I'm refreshing/learning C++ and am starting to learn Object Oriented Programming (OOP). In discussing this with people I came up short as to what the benefits of OOP are. For example: As I understand it, OOP has its main benefit in software reuse. Thus one develops a software library of classes and this cuts down the overhead of reinventing the wheel. Someone might say that this can be done with structured...
by: Rookie | last post by:
Is C an object oriented programming language?
by: Dale | last post by:
I've searched Amazon and read probably 100 reviews but can't find what seems to be any book that is widely accepted as the definitive book on object oriented programming design and techniques. And most of the highest rated are all written 10 to 15 years ago. Any good suggestions?
by: David Lozzi | last post by:
Howdy, I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user id, user name, full name, security level, department, etc.). Would I do better to create a class instead? Also, if I did, would I simply store the ID in the session and when accessing the class (User.FullName, User.SecurityLevel, etc.) then check the...
by: Mike Polinske | last post by:
I am new to the C programming language but have been programming in Cobol for over 10 years. When I compile the following code, it compiles clean but I get an application error both under Windows XP and Win2K. #include <stdio.h> #include <ctype.h> char title = "Year End Report";
by: Thierry Chappuis | last post by:
Hi, I'm interested in techniques used to program in an object-oriented way using the C ANSI language. I'm studying the GObject library and Laurent Deniau's OOPC framework published on his web site at http://ldeniau.web.cern.ch/ldeniau/html/oopc/oopc.html. The approach is very instructive. I know that I could do much of this stuff with e.g. C++, but the intellectual challenge of implementing these concepts with pure ANSI C is relevant to...
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented language. When I read things like "... C++ is an evolution of C ..." or "... C is a subset of C++ ..." I tend to believe that I will have to learn C+ + sooner or later. It sounds like C++ is the future and C is the past (and will be no longer...
by: Joe Mayo | last post by:
I think I become more and more alone... Everybody tells me that C++ is better, because once a project becomes very large, I should be happy that it has been written in C++ and not C. I'm the only guy thinking that C is a great programming language and that there is no need to program things object oriented. Many people says also that they save more time by programming projects object oriented, but I think its faster to program them in a...
by: notnorwegian | last post by:
i have some confusion over this. sure a class is basically a classification, like for example an animal or flower. and an object/instance of that class is then for example a cat. an object is an instance of a class. that i know, i also know how to program with classes etc. i am just confused about the term object-oriented.
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.