- class, object (and the difference between the two)
Class is a definition or blueprint of the object type.
Object is created from a class. Object's state and behavior usually undergo significant change during the execution of the program. - instantiation
The process of creating the object.
- method (as opposed to, say, a C function)
Method must be a member of a class whilst function can have independent existence. I think this only apply to Java. I never heard of a method in C/C++ or PHP. - virtual method, pure virtual method
Wow, I must admit that I could not remember this one. I must have been working with PHP and servers for so long. Anyway, a virtual method is a method whose behavior can be overridden within an inheriting class by a method with the same name and signature. If I remember correctly, this process is called method overriding.
REF: http://en.wikipedia.org/wiki/Virtual_function - class/static method
A static method can be called without creating the object. This is very useful in math calculation. - static/class initializer
I don't know. Will find out! - constructor
A special method that's being called at the creation of the object. - destructor/finalizer
Similar to constructor, destructor is called just before the object is destroyed. - superclass or base class
As the name implies, base class is the highest class in the hierarchy and does not inherit from any other class. - subclass or derived class
Subclass is a sometimes called a derived class. It inherits some properties from its base class. - inheritance
I think this is the most important feature of Object Oriented. It's the process in which a class inherits all the state and behavior from it parent class. Its parent class could further inherits from another class until the superclass is reached. - encapsulation
My lecturer Rob Allen usually said this whilst handling out the software project:
If I see public variable, you fail. You have been warned!
This is exactly what encapsulation is all about. There should be no direct access to the data member. - multiple inheritance (and give an example)
Most programming languages only support single inheritance. However, some programming languages like C++, Perl and Python do support multiple inheritance. An example would be:
a mermaid could inherit from fish and human. - delegation/forwarding
- composition/aggregation
A way to combine simple objects or data types into a more complex objects. An example would be: A bicycle has wheels, gears, chains... - abstract class
Class that cannot be instantiated. A superclass is usually an abstract class. - interface/protocol (and different from abstract class)
Similar to class, but it only has a list of method names and method signatures. When a class implements an interface, it must define all methods listed in the interface. - method overriding
When subclass overrides a method defined in the base class. Remember that the method name and method signature must be the same. - method overloading (and difference from overriding)
More than one method with the same method name can be created within a class. However, the method signatures must be different. This is called method overloading. - polymorphism (without resorting to examples)
I've been struggling with this concept since University. I still don't understand much about polymorphism. Anyway, this is what I think: there are 2 basic type of polymorphism; static and dynamic.
Static polymorphism allows programmer to create method with the same name but different method signature. This is method overloading.
Dynamic polymorphism is where the child class overrides a superclass method. - is-a versus has-a relationships (with examples)
Is a can be seen from inheritance while has a can seen from composition. An example would be:
Man is a Human
Man has a head - method signatures (what's included in one)
Method signature consisted of method name and parameters. E.g.
withdraw(int amount)
Note: return type are not considered to be as part of the method signature. - method visibility (e.g. public/private/other)
public - can be accessed by foreign class/object
protected - can be accessed by inherited class/object
private - can only be accessed locally within the class/object
Saturday, September 18, 2010
Fundamental Concepts in Object Oriented Programming
I never thought of this before reading Andrew Stuart blog. However, it's good for me to rehearse it before my university knowledge getting rusty. I work with PHP most of the time, so OO is not being utilized much. Let's see how I go.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment