how alive is oop?

Started by
25 comments, last by Tutorial Doctor 10 years, 2 months ago

Where-as the number of classes with virtual functions in any given project I can often count on one hand

OO teaches that you should default to composition as a default choice, and only use inheritance where truly needed and composition doesn't suffice. Virtual functions therefore should be quire rare in (statically typed) OOP code.

IMHO it was crazy for Java to default every function to being virtual, and for it to be encouraging a crazy amount of inheritance (both interface and implementation kinds). They've raised a whole generation of programmers who believe that implementation inheritance is the correct default tool for writing reusable code...

But yes, C++ is not an OO-specific language. It's multi-paradigm, letting you mix procedural, OO, generic, functional, meta-programming and probably other paradigms, within a statically-typed & pre-compiled framework.

One outgrowth of OOP are these static class methods used for math, instead of having global functions. What is the means of writing Math.Sin(x), instead of sin(x)? This is ridiculous in my eyes. Luckily, we don't have this nonsense in C++.

That's not an issue with OO itself; that's an issue with Java's perversion of OOP.

Advertisement
I hardly use object oriented programming at all unless I need it. For game programming, it works very well, because it simulates "game objects" very well.

You create one class for lights, and then you create light objects that automatically have the properties of lights.

Object oriented programming also simulates the actual world well too. There are classifications for everything. A classification for fruit and a classification for trees, for people, and for animals.

Since animals are so variant (even those of the same type and gender), you could create a classification for them using OOP and vary them slightly.

Object Oriented only means that the programming style is oriented towards a mindset that all things are objects, and have a classification that separates them from other objects.

But still, people always use a form of object oriented programming:

- A class of numbers containing integers, and floating point values?
- A class for logical operators?

Just guesses.

They call me the Tutorial Doctor.

There is also the Computer Science definition for OOP languages too which is that in a Pure OOP language all data types are actually first priciple objects. By that definition both C++ and Java are not OOP languages.

However the OP and most of the replies here are focusing on the engineering aspect of OOP which is obviously still alive and kicking.

I also use classes for everything ( even when used once ), exept for the main function ofcourse,

it makes things more managable, so you wont have globals shattered around.

S T O P C R I M E !

Visual Pro 2005 C++ DX9 Cubase VST 3.70 Working on : LevelContainer class & LevelEditor

I also use classes for everything ( even when used once ), exept for the main function ofcourse,
it makes things more managable, so you wont have globals shattered around.

Classes are not inherently object oriented. They are an organizational tool. The paradigm of an object-oriented approach does not require class and struct-style types. They make using that paradigm easier, but they are not a requirement.

There are many, many, many programming paradigms out there and you can be using many at once (see earlier in the thread). You can have classes and still be following an event-based paradigm, or be following an automata-based paradigm, or a flow-based paradigm.

Just because you are using classes and objects does not mean the code is following an object oriented thought process. Classes tend to guide toward that style, but that doesn't mean OOP dominates the processing paradigm.

Then its something i dont need to worry about, since i dont understand it fully.

One day i will understand it, thanks.

Goes above me for now.

S T O P C R I M E !

Visual Pro 2005 C++ DX9 Cubase VST 3.70 Working on : LevelContainer class & LevelEditor

Well, when you decide you want to finally figure it out, you can start with the section on Objects in my tutorial:

http://snapguide.com/guides/understand-computer-programming/

But to break it down here it works like this:

All fruit belong to the class of "Fruit"

Class Fruit

And fruit can have various properties that distinguish one from another, created as variables in the class (called member variables):

color =
shape =
taste =
texture =

And fruit usually have the same general "abilities' which are created as functions in the class (called methods):

beEaten()
fall()
grow()

Now we have a class for fruit. And now we can create a fruit object that will inherit the properties and abilities of the fruit class.

apple = Fruit()

Now that apple is a fruit, we can explicitly get the color of the fruit something like this:

apple.color

Based on how the class is set up, we can set the color this way:

apple.color = "red"

Perhaps you want to print the color of the apple?

print (apple.color)

Since we have that handy dandy class, we can create all sorts of fruit objects from it.

banana= Fruit()
orange = Fruit()
grape = Fruit()
 
grape.color = "purple"
banana.color = "yellow"
orange.color = "orange"

They call me the Tutorial Doctor.

This topic is closed to new replies.

Advertisement