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.
  1. 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.
  2. instantiation
    The process of creating the object.
  3. 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.
  4. 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
  5. class/static method
    A static method can be called without creating the object. This is very useful in math calculation. 
  6. static/class initializer
    I don't know. Will find out!
  7. constructor
    A special method that's being called at the creation of the object.
  8. destructor/finalizer
    Similar to constructor, destructor is called just before the object is destroyed.
  9. 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. 
  10. subclass or derived class
    Subclass is a sometimes called a derived class. It inherits some properties from its base class
  11. 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.
  12. 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.  
  13. 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.
  14. delegation/forwarding
  15. 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...
  16. abstract class
    Class that cannot be instantiated. A superclass is usually an abstract class.
  17. 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.
  18. method overriding
    When subclass overrides a method defined in the base class. Remember that the method name and method signature must be the same.
  19. 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.
  20. 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.   
  21. 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
  22. 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.
  23. 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

No comments:

Post a Comment