21.2.07

OO-Basics and Patterns

Object-oriented programming is a programming paradigm that uses "objects" to design applications and computer programs.


  1. Abstraction: In object-oriented programming theory, abstraction is the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system.

  2. Encapsulation: The principle of information hiding is the hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. Protecting a design decision involves providing a stable interface which shields the remainder of the program from the implementation (the details that are most likely to change).

  3. Polymorphism: is the ability of objects belonging to different types to respond to function calls of methods of the same name, each one according to an appropriate type-specific behaviour. The programmer (and the program) does not have to know the exact type of the object in advance, so this behavior can be implemented at run time (this is called late binding or dynamic binding). Polymorphism allows client programs to be written based only on the abstract interfaces of the objects which will be manipulated (interface inheritance). This means that future extension in the form of new types of objects is easy, if the new objects conform to the original interface. In particular, with object-oriented polymorphism, the original client program does not even need to be recompiled (only relinked) in order to make use of new types exhibiting new (but interface-conformant) behaviour (many pieces of code being controlled by shared control code).

  4. Inheritance: is a way to form new classes (instances of which are called objects) using classes that have already been defined. The new classes, known as derived classes, take over (or inherit) attributes and behaviour of the pre-existing classes, which are referred to as base classes (or ancestor classes). It is intended to help reuse of existing code with little or no modification. The main advantage of inheritance is that modules with sufficiently similar interfaces can share a lot of code, reducing the complexity of the program. Inheritance is also sometimes called generalization, because the is-a relationships represent a hierarchy between classes of objects.


Patterns

Patterns shows you how to build systems with OO design qualities. Good OO-Designs are reusable, extensible and maintainable. Patterns are proven OO-experience and they give general solutions to design problems, which can be applied to any specific application (they don't give the code).


Strategy Pattern

Strategy Pattern defines a family of algorthms, encapsulates each one and makes them interchangeable. Strategy lets the algorithm vary independentyl from clients that use it. The strategy pattern is useful for situations where it is necessary to dynamically swap the algorithms used in an application. The strategy pattern is intended to provide a means to define a family of algorithms, encapsulate each one as an object, and make them interchangeable. The strategy pattern lets the algorithms vary independently from clients that use them. Each set of behaviour is thought as a family of algorithms, which are intercahngeable (algorithms can be selected on-the-fly at runtime).

The UML class diagram for the Strategy pattern is the same as the diagram for the Bridge pattern. However, these two design patterns aren't the same in their intent. While the Strategy pattern is meant for behavior, the Bridge pattern is meant for structure.

Observer Pattern

Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. An example should be a newspaper subscription service with its publisher (i.e. Subject Object) and subscribers (i.e. Observers, one-to-many relationship). The Observer Pattern provides an object design where subjects and observers are loosely coupled, which means;



  • Changes to either the subject or an observer will not affect each other,

  • Subjects or observers can be used independently of each other,

  • Subject need not to be modified in order to add new types of observers,

  • New observers can be add any time,

  • The only thing the subject knows about an observer is: observer implements a certain interface.


Nvidia's GauGan App

NVIDIA's GauGAN AI Machine Learning Tool creates photorealistic images from Simple Hand Doodling http://nvidia-research-mingyuliu.com/...