Re: OO is not that great: many repeated codes
- From: "Daniel T." <daniel_t@xxxxxxxxxxxxx>
- Date: Fri, 22 Sep 2006 17:21:13 GMT
Shawn <shaw@xxxxxxxxxx> wrote:
I think OO is not great, compared to procedural languages. Each method
has to be hosted in one class. So the identical method code could be
repeatedly in several classes. I know inheritance /abstract classes/
interface concepts well. But please let me explain my point:
Professor and Student (two classes) know drive car well. So the method
void driveCarWell()
has to be in both classes.
HouseWife and Professor know how to cook. So the method
void cookDeliciousFood()
has to be in both classes.
Professor and Calculator (Two classes) can do some advanced calculation,
say find the average of two integers:
int average(int a, int b)
has to be in both classes.
Now the classes are like the following:
public class Professor
{
void driveCarWell()
void cookDeliciousFood()
int average(int a, int b)
...
}
public class Student
{
void driveCarWell()
...
}
public class HouseWife
{
void cookDeliciousFood()
...
}
public class Calculator
{
int average(int a, int b)
...
}
As you see, methods are repeated in many classes. It is hard to use
inheritance to solve the issue.
I don't feel like others directly addressed the example...
(Python)
class Student:
def driveCarWell(self):
pass
class HouseWife:
def cookDeliciousFood(self):
pass
class Calculator:
def average(self, firstNum, secondNum):
pass
class Professor (Student, HouseWife, Calculator):
pass
Where's the duplication?
Particularly, Professor and Calculator cannot share a superclass in
real world.
Why not? (Keep in mind also, your example isn't very "real world" in any
case.
And in Java, there is no multiple inheritance.
What does that have to do with OO?
In procedural language, you only need to write the method once and
put them in the global place. Then you can grab them anytime you
want. Because a method don't need to be buried inside a class.
I've seen that method used as a sort of psudo-OO. If you want to
implement an OO language in a procedural one you are welcome to. I
prefer not re-inventing the wheel myself. At least in this case.
--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer have anyone to discuss your doubts with,
nor any ability to discuss them.
.
- Follow-Ups:
- Re: OO is not that great: many repeated codes
- From: Bruno Desthuilliers
- Re: OO is not that great: many repeated codes
- References:
- OO is not that great: many repeated codes
- From: Shawn
- OO is not that great: many repeated codes
- Prev by Date: Re: OO is not that great: many repeated codes
- Next by Date: Re: Abstract public member variales?
- Previous by thread: Re: OO is not that great: many repeated codes
- Next by thread: Re: OO is not that great: many repeated codes
- Index(es):
Relevant Pages
|