WSQ03 – Object-Oriented Basics

After watching this video I know a lot more about the concept of object-oriented programming (OOP).

Working with objects is quite different from procedural programming. In many cases it’s more useful for developers since it’s closer to real life problems.

Furthermore I learned about some terms and concepts such as:

  • Static / dynamic typed languages:
    • static: Do type checking at compile-time (e.g. Java, C#, C++).
    • dynamic: Do type checking at run-time (e.g. Python, Javascript).
  • Classes: Basically a data type definition, made of its members, the fields and the methods
  • Objects: Instances of classes
  • Encapsulation: The fields of an object should only be read and written by invoking the methos of this class. If you follow this principle, the code gets easily modifiable. If not, you soon get «spaghetti code».
  • Public / private members of a class:
    • Public members can be accessed by methods from other classes.
    • Private members can only be accessed by methods of the same class. If you want to follow the concept of encapsulation strictly, all fields of a class should be private.
  • Inheritance:
    • If the class a  inherits from class b, and b inherits from the class c, then b contains all members of c and a all the members from b (and therefore also the members of c).
    • a and b are subtypes (or descendants) of c. b and c are supertypes (or ancestors) of a.
    • Direct subtypes are called childs. Direct supertypes are called parents.
    • Inheritance is used between classes that have a is-a relationship. Not a has-a relationship. (E.g. a cat is a kind of a mammal.)
    • Some programming languages allow multiple inheritance.
    • If an ancestor has the same method than one of his ancestors, it get overwritten, so that the methods  can be made more specific for the subclasses.
  • Polymorphism: The choice of the method being invoked depends on the object which is chosen as an argument.
  • Class members: Members of the class itself and not of its instances. In Java they’re called static members. There are reasons for them to exist, but using a lot of those members is not object-oriented.
  • Constructor: Method which is run in order to set up an instance of a classes. How he looks like is context dependent.
  • Interface: If there are different classes which are not related but share the same set of methods in common, an interface can be created to form a bundle of methods which can be used by those classes.
  • Abstract class: A class that just serves as ancestor for other classes and which is not meant to be instanciated itself. (E.g. it doesn’t make sense to instanciate the class «mammal» because there is no «the mammal».)
WSQ03 – Object-Oriented Basics

2 comentarios en “WSQ03 – Object-Oriented Basics

Deja un comentario