BLM> Correct any of this if it is wrong please.
DM> Ok. :-)
BLM>
BLM> I am forever in you debt. |)
Can I get the payment in BEvERages? :-)
BLM> "Object Oriented Programming" is mostly hype...
DM> There is a lot of hype with OOP, as there has been with any other
DM> "real" programming advance. That doesn't mean it isn't valid -
DM> only that MS has gotten a hold of it. :-)
BLM>
BLM> I didn't mean to imply that OOP is an invalid concept, just that it is
BLM> only a concept and not a programming language. From what I have
learned
Right. OOP is a concept. An OOPL is a language. :-)
BLM> so far OOP is the best way to develop complex
BLM> applications. Note: what I
It is merely the "current fad" in developing complex applications. :-)
BLM> have learned so far about object oriented programming can fit here
->[].
BLM> But I haven't given up. |)
Never give up. Merely take strategic retreats every once in a while. :-)
DM> First of all, OOP is a complete paradigm shift (to use an already
DM> overused term) from "structural" programming.
BLM>
BLM> Believe it or not, I'm willing to change the way I look at things. I
BLM> always thought I had a very open mind.
When I "jumped aboard" the OOP bandwagon, it was because I found the OOP way
of working much more "natural" to me. If you can't embrace the concepts,
it's a very poor way of making a living. OTOH, if you can embrace it, then
you'll think that structural/modular programming is a poor way to make a
living. :-)
DM> It is a complete change in design and thought about programming.
BLM>
BLM> Perhaps you could give an example here. I have been programming as
BLM> a hobby for some years now and have used everything from Asic to
BLM> Modula-2. From all power no structure to all structure no power |).
BLM> Is OOP the happy medium?
OOP isn't the "answer" to everything, it's merely a method of solution of a
large number of problems. Rather than thinking along a "line" of
programming, one thinks about objects that DO things. For example, a car.
A car has an engine. You apply gas to it, and it goes faster. So, if you
were to, say, apply gas to the car, the car would take the gas and apply it
to the engine. The engine would take the gas and run a conversion from gas
to kinetic energy, and apply this kinetic energy to the axle(s). The axles
would apply this kinetic energy to the wheels. The wheels would apply it to
the road. The road would then respond by applying a speed increase to the
wheels, which would make the entire car go faster.
int main()
{
Car car;
...
car.gas(1);
...
};
void Car::gas(int GasAmt)
{
int newenergy =
engine.gas(GasAmt); // member variable "engine" which is of type Engine
energy += newenergy; // energy is a member variable of type int
speed = sqrt(energy / 2 / mass); // speed & mass are member variables
}
int Engine::gas(int GasAmt)
{
int energy = ConvertGasToEnergy(GasAmt); // Convert is a private member
unc
return axle.apply_energy(energy); // member variable "axle" is type Axle
}
int Axle::apply_energy(int EnergyAmt)
{
return left_wheel.apply_energy(EnergyAmt / 2) +
right_wheel.apply_energy(EnergyAmt / 2);
// left_wheel and right_wheel are member variables of type Wheel
}
int Wheel::apply_energy(int EnergyAmt)
{
// LookupRoadCondition returns a reference to a global road condition
// current_position is a member variable of type position
Road& CurrentRoad(LookupRoadCondition(current_position));
return CurrentRoad.apply_energy(EnergyAmt);
}
Road::apply_energy(int EnergyAmt)
{
if (coefficient_of_friction_is_high_enough)
{
return EnergyAmt;
}
else
{
return EnergyAmt * coefficient_of_friction;
}
}
Now, this likely could have been done MUCH more compactly without objects.
However, with this, we can have a motorcycle (also with wheels - the axle
would have to be removed), or whatever, and still have the "heart" of the
program the same. It's a matter of reusable code ... that fill out the
details of an object.
BLM> Classes are the basic building blocks of C++ programs just as
BLM> functions are the basic building blocks of C programs.
DM> OBJECTS are the basic building blocks of an OOPL, in general.
BLM>
BLM> Please define OBJECT. I think this is one of my sticking points.
BLM> Is an object a class? Is a class an object? How do you create
An object is an instance of a class.
class foo{}; // foo is a class.
foo f; // f is an object
--- Maximus/2 3.01
---------------
* Origin: Tanktalus' Tower BBS (PVT) (1:342/708)
|