Browse Source

updating readme with rearranged OOP examples, info about design patterns

master
Charles Reid 5 years ago
parent
commit
fb4559e040
  1. 48
      README.md

48
README.md

@ -45,49 +45,29 @@ Objects in memory:
* How to check if two objects are equal?
* How to store pointers or references to objects?
### OOP
Basic object oriented programming concepts:
* simple object with single constructor, couple of methods
* object comparison, object iteration
* overloading - more complicated objects overloading constructors/methods
* inheritance diagram
* polymorphism for function parameters
* objects in memory
### Computer Science-Related
Design patterns:
* https://en.wikipedia.org/wiki/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.
Basic data structures:
* Linked lists
* arraylists
* Graphs
* Binary trees
* Recursion/backtracking with 8 queens or permutation problem or other
Other design patterns:
* Iterable
* Factory
* Singleton
## Design Patterns
## Design Templates
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.
### Iterable
This basically explains why Go does "OOP" the way it does.
Iterable makes a data container iterable.
### Factory
Factory methods control/wrap objects and the object-creation process.
They usually take care of the details of object crreation, storage, and retrieval.
For example, the scalar equation factory is used to generate new equations with given properties.
IF you need the equation for a variable, you no longer need the equation object, you just need the factory and the equation label.
Then you say, getEquationByLabel("mylabel")
### Singleton
A singleton design pattern restricts a class to having only a single instance.
Factory is usually a singleton (or a function).
When you construct the class, it creates one instance of itself as a static variable (private).
When you ask for the class, it will either return the static instance, or (if it has not created it yet) will create it, then return it.

Loading…
Cancel
Save