Some "hello world"-style object oriented programs. These will get you started writing object oriented programs in various languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Charles Reid 1eb88986af adding polynomial objects, quadratic object to illustrate Java inheritance. 4 years ago
c++ adding C++ hello world and rectangle classes 4 years ago
go p.s. 4 years ago
java adding polynomial objects, quadratic object to illustrate Java inheritance. 4 years ago
perl updating Perl OOP readme 4 years ago
python minor fixes to Python readme 4 years ago
README.md updating readme with rearranged OOP examples, info about design patterns 4 years ago

README.md

hello-oop

Some “hello world”-style object oriented programs. These will get you started writing object oriented programs in various languages.

Inspired by Rosetta Code

Object-Oriented Languages

A Partial List of Languages:

  • java classes

  • python classes

  • perl classes

  • c++ classes

  • c structs (?)

  • octave objects (?)

  • go

  • php classes

  • ruby classes

List of Programs/Classes

For each language, we try to illustrate a few key behaviors.

Basic object operations:

  • Point object to illustrate a basic object with a Cartesian point
  • Point object to illustrate comparisons of objects/equality checking
  • Point3D object to illustrate iteration
  • Widget object to illustrate printing “Hello World” from an object method

Morphing objects:

  • Shape object to illustrate inheritance (Circle, Rectangle, Triange)
  • Shape object to illustrate interfaces (getArea, getPerimeter)
  • Floorplan object to store Shape array, sum areas of each, to illustrate polymorphism

Private objects:

  • How to protect data, while also providing public accessors to get/set
  • How to make data truly immutable?

Objects in memory:

  • Point3D object to illustrate how objects are dealt with in memory
  • If we say point2 = point1, what really happens?
  • Illustrating a copy constructor (taking object of type self)
  • How to check if two objects are equal?
  • How to store pointers or references to objects?

Design patterns:

  • Recursive composition - hierarchical structure of elements that builds increasingly complex structures out of simple ones; when operations performed on parent, operation is recursively passed down hierarchy.
  • Composite pattern - collection of nodes to make up a whole.
  • Compositor - has an associated instance of the Composition object; when Compose() called, iterates through each composition element and rearranges structure as needed.
  • Strategy pattern - encapsulate multiple algorithms to be used based on changing context.
  • Transparent enclosure - layering elements augmenting overall composition beahvior onto the composition; elements are subclasses of singular element itself; augmenting composition by adding state-like elements.
  • Decorator pattern - decorators add behavior to an individual object, without affecting behavior of all other objects of the same type. (Decorator is subclass with pointer to parent, parent instance is passed to constructor, decorator forwards all parent methods to parent, overrides any methods that need to be modified). Decorators can stack. Subclassing is a compile-time modification, decorators are a run-time modification.
  • Abstract factory pattern - abstracts the object creation process; different concrete implementations are possible.

Other design patterns:

  • Iterable
  • Factory
  • Singleton

Design Patterns

Following the advice of the “Gang of Four” book on design patterns in programming, the authors recommend programming to interfaces, not to implementations, and recommend object composition over class inheritance.

This basically explains why Go does “OOP” the way it does.