Jump to content

tricky oop concepts

- - - - -

  • Please log in to reply
2 replies to this topic

#1
desir

desir

    Newbie

  • Members
  • Pip
  • 5 posts
Hello,

I'll be taking a general oop knowledge test. I know there will be a question where I need to select which concepts are not related to oop. It comes down to selecting one of "Multi-tasking" and "Type casting". Which is related to oop and which not?
Also, what is the difference between abstraction and encapsulation. I know they both refer to hiding or organizing information.
What other concepts should I look up? I've only heard about: inheritance, polymorphism, encapsulation and abstraction.
I'd be grateful if you guys could clarify these for me.
Cheers!

#2
alan2here

alan2here

    Newbie

  • Members
  • Pip
  • 5 posts
OO is an Abstraction, so this turm covers everything to do with it.

Encapsulation is what I think of as the most key part of OO. Things exist, they have names and can contain other things. For example an animal may contain limbs, an outer surface area, information about how it sounds and moves etc... A _branch_ of a tree could even contain other _branch_es that are sprout from it. All thease things are examples of encapsulation.

So far this is object based. Langueges like Javascript do powerfull things with just the object based approach and there are benifits to stopping here, full OO however implements some further concepts.

One is that thease things are instances of classes. A class describes what the thing is all about but each instance of the class can vary according to how to define the class. An advantege to this is that if you want 3 apples you can be sure that all 3 will have cirtain apple qualities in common, even in the surface color varies.

Polymorphism is when things behave contextually. A simple example of this is when two functions have the same name but different parameters, however you may instead be asked more complicated questions about it's relation to inheritance.

Inheritance is a way of organizing classes into a sort of tree so that the languege can deal with cirtain things to do with polymorphism, classes can optionally inherit from each other, if a class inherits from more one other class it's referred to as multiple inheritance. Inheritance is thought of differently than encapsulation.

An example of inheritance using the earler animal example is that there might be a rabbit class thats a sub-class of animal, so rabbit shares some things in common with animal but others are specifically rabbit related.

Encapsulated elements are often said to be more of a "has" relationship wheras inherited elements are more of an "is" relationship.

Classes can contain/encapsulate members. Where thease members are functions they are referred to as member functions or methods.

Type-casting converts one type into another, for example int to float, often this is a built in feature of the languege, obviously not all types make sence to cast, again using examples above animal and apple probbably don't share enough in common that type casting between them makes sence. You can provide methods to cast, or perform an equivalent action in your own classes, a common example is toString().

Multi-tasking seems like the odd one out here, I think it means having multiple things occur at the same time, this not a specifically OO thing but it's cirtainly possible in an OO enviroment. If you use C# for example try the "parallel for".

C++ is probbably the most popular OO languege, although I don't like it at all. C# and Java both have garbage collection, as I see it this makes code written in them more reliable.

#3
alan2here

alan2here

    Newbie

  • Members
  • Pip
  • 5 posts
Was this helpfull?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users