Encapsulation and Polymorphism...What the? (1 Viewer)

jizmiester

Member
Joined
Aug 23, 2003
Messages
171
Location
Dully Hill, Sydney
Can someone please explain to me the real concepts behind these terms? My teacher kind of rushed it and gave the both fu*kd definitions! Any help would be very much appreciated :D
 

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
Old syllabus maybe? I have never heard these terms in context of SDD, but remember something 'like' that in yr 10 stuff...
 

Ragerunner

Your friendly HSC guide
Joined
Apr 12, 2003
Messages
5,472
Location
UNSW
Gender
Male
HSC
2003
This is in the Option topic: Evolution of programming languages.

Encapsulation - The process of hiding an objects data and processes from its environment. Only the object can alter its own data.

Polymorphism - The ability to appear in many forms. In OOP this means at runtime a method can process data differently depending on the circumstances.
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
A good discussion on various defintions of encapsulation can be found at
http://www.itmweb.com/essay550.htm

And for polymorphism check out this pdf
http://www.ida.his.se/~jonas/ComponentSoftwareCourse/ch6-team2.pdf

I think both these document are relatively understandable and provide general discussions not related to a particular language. There are many common examples of polymorphism, consider the + operator, in most languages this single operator is used to add integers, floating-point and even to concatenate strings. Therefore 1+2, 1.234+34.09 and "Hello"+"World" all initiate very different functions, hence + is a polymorphic function (this is an example of overloading; a type of polymorphism). Also the + operator is able to alter the type of the result, so if we do an integer addition where the result is outside the range that can be represented as an integer then it is turned into a floating-point (this is another type of polymorphism called coercion).

HTH
Sam
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
I'd also like to point out Polymorphism is also in reference to a form of virus, which has the ability to modify itself while it replicates, this is in attempt to prevent AV's from detecting it.
 

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
Ahah... That would explain why I hadnt heard them... Being a hardware person.
 

Ragerunner

Your friendly HSC guide
Joined
Apr 12, 2003
Messages
5,472
Location
UNSW
Gender
Male
HSC
2003
I would also like to point out polymorphism is a spell used in warcraft 3. It turns a living organism into a sheep for 60 seconds that can't attack.

COOL

disregard that :D
 

Chand

Reflect the lights
Joined
Mar 29, 2003
Messages
871
Location
In the heavens
Gender
Female
HSC
2003
Originally posted by Winston
I'd also like to point out Polymorphism is also in reference to a form of virus, which has the ability to modify itself while it replicates, this is in attempt to prevent AV's from detecting it.
Thats IT not SDD:p...
 

Rahul

Dead Member
Joined
Dec 14, 2002
Messages
3,647
Location
shadowy shadows
Originally posted by Ragerunner
I would also like to point out polymorphism is a spell used in warcraft 3. It turns a living organism into a sheep for 60 seconds that can't attack.

COOL

disregard that :D
sorcerors in humans i think ;)
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
A morph is a single distinct form, usually an animal e.g. a caterpillar is a morph of a butterfly. Poly means many, so polymorphism is the ability to take on different forms whilst still being the same thing. ie. both the caterpillar and the butterfly are genetically the same but quite different. Hence the word polymorphism has been nicked from general usage and used within programming and Warcraft 3 and as the name of a form of virus.
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by SamD
A morph is a single distinct form, usually an animal e.g. a caterpillar is a morph of a butterfly. Poly means many, so polymorphism is the ability to take on different forms whilst still being the same thing. ie. both the caterpillar and the butterfly are genetically the same but quite different. Hence the word polymorphism has been nicked from general usage and used within programming and Warcraft 3 and as the name of a form of virus.
So that's how Power Rangers came to light "It's morphing time" lol :p
 

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
Also BTW, Is there much of a difference between abstraction and encapsulation ?
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Check out the link I posted earlier in this thread
http://www.itmweb.com/essay550.htm

It explains both abstraction and encapsulation.

In simple terms:
Abstraction is about consdering only the relevant bits needed to solve a part of problem and sort of ignoring the big picture. For example if you're coding a sort you could write a subroutine to do a swap, when writing the swap you ignore the detail of the whole sort and just concentrate on the swap. That is, you just need two elements and you just need to return them the other way around.

Encapsulation is about hiding detail about both the processes taking place and the internal data. In a sense encapsulation results in a black box, only the inputs and outputs (interface) are exposed to the environment. For example a control, such as a text box, in VB exposes various properties and events via its interface but the processing resuting from altering a property is hidden, you just understand what the result or output will be. ie. if you alter the justification of the text you don't care how this is implemented it just works.

HTH
Sam
 

Foong

Member
Joined
Aug 23, 2003
Messages
75
Even though you do hardware, you still should know them. This is because the past years SDD has always been written badly, and stuff from the option topics tend to be asked in the multiple choice section and in one or two cases the short answer questions, so be careful

encapsulation and polymorphism are the essential basics of object orientation programming which makes it different to procedural programming. If you have done object orientation programming this would be easier to explain. OOP divides code into deifferent cells or structures, or boxes or modules or watever u want to call them. You cannot see the code, but you can pass information out and recieve information. i think i should stop there as SamD and other explained it, although my definition IMHO is better but i can't be bothered to go into my room and get my notes now, maybe another day b4 SDD exam
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top