Archived

This topic is now archived and is closed to further replies.

null_pointer

Definition of OOP

Recommended Posts

iwasbiggs    122
It''s all heresay

To me OOP is anything in which you create your variables and use them. So anything that isn''t OOP would be more of a scripting language in which you might use pre-determined variables or none at all.

Share this post


Link to post
Share on other sites
Mezz    571
Since, as you say there are a lot of articles that disagree, you could come to the conclusion that either

a) No-one actually knows.

or

b) It''s a subjective definition.

Myself, well I define it as using logical objects to define a heirarchy and structure in a program, using encapsulation to provide safe and consistent access to members and ensuring that it is easily expandable.

But that''s probably crap, so let''s just say no-one knows

-Mezz

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
no..
OOP is where you use objects such as classes and structs to group and structure your data logically.

The alternative to this is procedural programming. The old BASIC is this as anyone who knows it knows what i mean, there''s no real structure, you take your program statement by statement.

Share this post


Link to post
Share on other sites
Jrz    122
VB is not fully OOP, C++ neither
java is though...

but hey, I''d rather do RND or rand() than Math.random()

Share this post


Link to post
Share on other sites
nicba    122
To be considered Object Oriented I think a language has to cntain at least the following 3 features:

1. Encapsulation
2. Inheritane
3. Polymorphism

On top of ths there is some "extra" features and differences between the implementation of differend object oriented languages.

Some languages (Object Pascal and Java) lets all classes inherit at least from a default class (Pascal: TObject, Java: Object). Thus all objects ever created will always be a part of one large inheritance three. This might be considered a requirement too.

C++ has multiple inheritance, that is a class can inherit from two or more parent classes. Java does not. In Java you can only inherit from one class. This is not simply done out of technical concerns but because the Java designers thought that multiple inheritance was not a "good" or propper OOP.

In return Java have the concept of Interfaces (which can sometimes be used in place of multiple inheritance). Interfaces plays a rather big role in some object oriented methologies but is it a part of OOP? Well not the original definition I think but OOP is not a static definition but is still evolving.

PS: Marco Cantù has a papper on his web-site titled "Comparing OOP Languages: Java, C++, Object Pascal" which you might find interesting. I did.


Regards

nicba

Share this post


Link to post
Share on other sites
null_pointer    289
nicba:

heh heh I like yours the best! (null likes C++)

I''m not dead-set against Java or anything, but it seems that there are two problems:

1) deriving all objects from a base object
2) multiple inheritance


#1 one hierarchy, aka CObject

This is usually used to address some perceived shortcoming in the C++ language, and is generally considered an obvious indicator of bad design (which in turn stems from lack of knowledge about the language or the problem domain, or both). There is never a good solution for _all_ classes, however. Not even with simple things like instance counting... Even the MFC programmers know that!

Besides, the name doesn''t even make sense. When you define a class, you define a class. When you define an object, you define an object.


// declare an instance of a class
// (this is also called defining an object!)
CClass MyObject;




class CObject {}; // wrong! this is _not_ defining an object!



Remember:
class = type
object = instance


#2 multiple inheritance

I don''t think multiple inheritance is bad. The way many people use it is bad, though. However, when used properly, it is a real timesaver and definitely a good programming tool.

Example:


class input_stream
{
public:
virtual void read(void* data, int size) = 0;
};

class output_stream
{
public:
virtual void write(void* data, int size) = 0;
};

// now what do we do when we want both?

class file
: public input_stream, output_stream
{
public:
virtual void read(void* data, int size) { /* implement this */ }
virtual void write(void* data, int size) { /* implement this */ }
};



Some classes do not need to do both input and output and thus they are not derived from both input_stream and output_stream, but some classes do need to do both input and output are derived from both (like the file class).

This is important, because you may have an object that can do both input and output, but you have a stream class that can only do output (or input) but not both. You want only one syntax to be valid, so you let the compiler use the class hierarchy determine whether or not the stream supports the methods.

Without multiple inheritance, you would have to add in the read/write methods yourself. Also, that approach still prevents you from using the abstract classes, and it undermines the power of data streams, which is to be able to send the same data to different destinations in the same way. If you use an abstract class without multiple inheritance (which has both read and write) that would leave some methods unimplemented on some classes (which is a, how do you say it? "boner"?).

Ideal solution? Multiple inheritance.


However, I do not want this to turn into a language war - just a reasonable topic on programming methodologies.


Jrz:

How is C++ not an OOP language?


Mezz:

If OOP is subjective (which I doubt), then it is useless as a methodology.




- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by nicba

To be considered Object Oriented I think a language has to cntain at least the following 3 features:

1. Encapsulation
2. Inheritane
3. Polymorphism



This would imply that VB IS an object oriented language..


VB supports Encapsulation via classes or UDTs.

VB supports Inheritance through the keyword Implements. Although, VB doesn''t support implementation inheritance (at least at last glance), meaning you have to reimplement all the methods of the parent class. You didn''t specify that you had to LIKE the way OO features were implemented.

VB supports Polymorphism as you can redefine the behavior of the parent methods in your child class. Also provides runtime identification of classes (RTTI). VB also supports the concept of an abstract class.







Share this post


Link to post
Share on other sites
ImmaGNUman    122
Actually, OOP theoretically should be possible in any procedural language, which it is, C, Pascal, etc. all have ways of doing it. But VB isn''t an OOP language, completely. It supports *most* OOP features, but not all. Although, it is correct to say VB is not a programming language but a scripting language with an application builder.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

Share this post


Link to post
Share on other sites
40 Thieves    122
I would have to say that Java is not OOP.... it is Object Based. There is no decision, when writing a Java program, as wether or not to use objects.... The program itself is an object, and everything within Java is an object. Therefore I would conclude that Java is OBP instead of OOP.

40

www.databyss.com
www.omlettesoft.com

"Don''t meddle in the affairs of wizards, for they are subtle and quick to anger."

Share this post


Link to post
Share on other sites
DarkMage139    294
I''m not criticizing Java or anything, but sometimes I think Java was made to keep you from hurting yourself...

- DarkMage139
++++++++++++++++
I can do things, things you never knew,
I can change your world if you only knew.

I can do miracles if you want me to.
Anything is possible, I'll prove it to you.

Share this post


Link to post
Share on other sites
nes8bit    275
quote:
Original post by ImmaGNUman
Although, it is correct to say VB is not a programming language but a scripting language with an application builder.


I suggest you actually know something about VB before posting. VB has a native compiler which compiles to native code. It is defaulted to to that. VB4 and lower did not. It has P-Code. Either way, it isn''t a scripting language.

And to the Anon Poster, I hope you''re right. I don''t have the slightest clue on what those 3 things are. Although I know what implements does. :p

------------------------
Captured Reality

Share this post


Link to post
Share on other sites
nicba    122
OK, I do not know VB and I really do not care if it is OOP or not, so don''t take this wrong. But I have some question about VB.

quote:
Original post by Anonymous Poster

VB supports Encapsulation via classes or UDTs.




What''s UDT''s???

quote:


VB supports Inheritance through the keyword Implements. Although, VB doesn''t support implementation inheritance (at least at last glance), meaning you have to reimplement all the methods of the parent class. You didn''t specify that you had to LIKE the way OO features were implemented.




No implmention inheritance?? Strange. It sounds almost as if VB classes is really interfaces (Java also uses the keyword ''implements'' when dealing with interfaces).

quote:


VB supports Polymorphism as you can redefine the behavior of the parent methods in your child class. Also provides runtime identification of classes (RTTI). VB also supports the concept of an abstract class.




Well, redefining (overriding) parent methods isn''t really what is understood by Polymorphism. Polymorphism is when you use late binding (compiler time binding) to call methods of a child class through a pointer to a parent class. Example:

You have 3 differend classes in your game Animal, Dog and Cat. Animal have the public method Sound() which both Dog and Cat inherits and overrides. Now you want to store a list of both dog''s and cat''s in an array so you creates an array of pointers to Animals (but let your pointers point to Dog and Cat objects). Then when you loop through the array calling the sound() method for each item the compiler would use polymorphism to determind which sound() method to call by determinding (at runtime) which class your pointer really pointed to. Without polymorphism the compiler would already had hard-wired these function calls to the sound() method of the parent class Animal since all your pointers pointed to that class.

I hope I made myself somewhat clear. Now, could someone tell me if VB still supports Polymorphism?

Regards

nicba



Share this post


Link to post
Share on other sites
nes8bit    275
quote:
Original post by nicba
Well, redefining (overriding) parent methods isn''t really what is understood by Polymorphism. Polymorphism is when you use late binding (compiler time binding) to call methods of a child class through a pointer to a parent class. Example:

You have 3 differend classes in your game Animal, Dog and Cat. Animal have the public method Sound() which both Dog and Cat inherits and overrides. Now you want to store a list of both dog''s and cat''s in an array so you creates an array of pointers to Animals (but let your pointers point to Dog and Cat objects). Then when you loop through the array calling the sound() method for each item the compiler would use polymorphism to determind which sound() method to call by determinding (at runtime) which class your pointer really pointed to. Without polymorphism the compiler would already had hard-wired these function calls to the sound() method of the parent class Animal since all your pointers pointed to that class.

I hope I made myself somewhat clear. Now, could someone tell me if VB still supports Polymorphism?

Regards

nicba


God that was confusing...thanks for clearing it up.

Anyhoo, if you put it that way, yes VB does support polymorphism. Using Implements it can do that. That''s how I made plugins for the Captured Reality Engine.

If you understand VB and have VB, try this link. Patrice Scribe shows how to make plugins with Implements and such. Tell me, is that polymorphism?


------------------------
Captured Reality

Share this post


Link to post
Share on other sites
40 Thieves    122
quote:
Anyhoo, if you put it that way, yes VB does support polymorphism. Using Implements it can do that.


How does this implements thing work... and can they be changed during runtime? Let me use the classes mention by that dude before... Animal as the parent class and Dog and Cat as the subclasses... In C++ when you construct your classes this way using virtual functions (or how you want it) you actually create both objects... say you do this:

Animal* ptr=0;

now during runtime i can execute this:

ptr = new Dog;

ptr->Sound(); // executes the Sound() function in the Dog class

ptr.Sound(); // executes the Sound() function in the Animal class

Further in my program if needed i could do this:

ptr = new Cat;

ptr->Sound(); // executes the Sound() functino in the Dog class

ptr.Sound(); // again back to the Animal class

and I can modify these all i want during my program with if's and stuff... during runtime... so it's called a runtime polymorphism... is this possible in VB using implements?

40

www.databyss.com
[a]http://www.omlettesoft.com'>www.omlettesoft.com

"Don't meddle in the affairs of wizards, for they are subtle and quick to anger."

Edited by - 40 Thieves on July 23, 2000 7:01:50 AM ' Target=_Blank>Link

Share this post


Link to post
Share on other sites
nicba    122
quote:
Original post by nes8bit

God that was confusing...thanks for clearing it up.

Anyhoo, if you put it that way, yes VB does support polymorphism. Using Implements it can do that. That''s how I made plugins for the Captured Reality Engine.

If you understand VB and have VB, try this link. Patrice Scribe shows how to make plugins with Implements and such. Tell me, is that polymorphism?




I don''t know anything about VB. I have never owned VB and have never had a chace to look at VB code before.

But anyway I took a quick look at the link you provided and to me it seems like it is polymorphism allright. And I saw that it had the ''public'' and ''private'' keywords also, so encapsulation is also OK.

The only issue left is then inheritance. If you can''t inherit implementation in VB then you don''t really have that much to inherit. You can''t inherit an objects behaviour only its definition (much like Interfaces as I said before). Haven''t VB got an ''extend'' keyword or something?

Regards

nicba

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster

nicba -

Thanks for providing a clear example on polymorphism. Dunno where my head was at when I posted, but I bet you could hazard a guess.

A UDT in VB is a User Defined Type, basically a struct in C.

40 Theives-
For your example of polymorphism, VB can do that easily:

    


Dim theDog As IAnimal
Dim theCat As IAnimal
Dim theAnimals As New Collection



''
'' ojbect creation
''
Set theDog = New Dog
Set theCat = New Cat

''
'' add to our collection
''
theAnimals.Add theDog
theAnimals.Add theCat

''
'' iterator for our collection
''
Dim animal As IAnimal

For Each animal In theAnimals

''
'' sounds off for each animal
''
animal.Sound

Next

''
'' explicitly call objects Sound method
''
theDog.Sound
theCat.Sound


''
'' clean up
''

Set theDog = Nothing
Set theCat = Nothing




[/source]


Yes, in VB inheritance is very similar to using interfaces...the difficulty is that you have to re-implement all of the parent class/interfaces properties and methods in your derived class..its a big issue within VB (as in it sucks ..).

Here is a sample of the Dog code implementing the IAnimal interface:


[source]
''
'' dog.cls
''
Implements IAnimal


Public Sub IAnimal_Sound()

Debug.Print "Woof"

End Sub




You have to do that for EVERY method/property of IAnimal..so while Inheritance is supported...the support leaves alot to be desired.


-Z


Share this post


Link to post
Share on other sites
null_pointer    289
40 Thieves:

You can''t use the . operator on a pointer, unless you do this:


(*ptr).Sound();



Which is defined to mean exactly the same thing as the -> operator. A virtual function is a virtual function - you can''t mix and match where you want (because it wouldn''t make any sense). However, you can call any of the base class versions from within a derived class''s virtual function:


class Animal
{
public:
virtual void Sound() {}
};

class Dog
: public Animal
{
public:
virtual void Sound() { Animal::Sound() }



heh heh I don''t know how the VB discussion got started, but it''s interesting...I used QBASIC so long ago...ah, memories...

But what _is_ the technical definition of OOP?




- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites
ImmaGNUman    122
VB still requires runtimes from my knowledge and it is possible to create an executable without writing ANY code (course it will suck). And yes, i have programmed a little VB myself.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

Share this post


Link to post
Share on other sites