Commit 227f7c56 authored by michael lundquist's avatar michael lundquist
Browse files

Starting ch 2.

parent 73c9016b
......@@ -67,7 +67,7 @@
### 2.1.3 Design Patterns
- __Object-oriented design patterns__ provide a general template solutions for many problems that are concise, correct, and reusable.
- __Object-oriented design patterns__ provide general template solutions to many problems that are concise, correct, and reusable.
- These design patterns consist of:
- a *name*
- a *context* in which to apply the pattern
......@@ -76,23 +76,72 @@
- This book presents 2 groups of design patterns:
1. patterns for solving algorithm design problems including:
- Recursion (Ch 5)
- Amortization (Sections 7.2.3, 11.4.4, and 14.7.3)
- Divide-and-conqure (Section 12.1.1)
- Prune-and-search, aka decrease-and-conqure (Section 12.5.1)
- Brute force (Section 13.2.1)
- The greedy method (Sections 13.4.2, 14.6.2, and 14.7)
- Dynamic programming
- Recursion (Ch 5)
- Amortization (Sections 7.2.3, 11.4.4, and 14.7.3)
- Divide-and-conquer (Section 12.1.1)
- Prune-and-search, aka decrease-and-conquer (Section 12.5.1)
- Brute force (Section 13.2.1)
- The greedy method (Sections 13.4.2, 14.6.2, and 14.7)
- Dynamic programming
2. patterns for solving engineering problems:
- Template method (2.3.3, 10.5.1, and 11.2.1)
- Composition (Sections 2.5.2, 2.6, and 9.2.1)
- Adapter (Section 6.1.3)
- Position (Sections 7.3, 8.1.2, and 14.7.3)
- Iterator (Section 7.4)
- Factory Method (Sections 8.3.1 and 11.2.1)
- Comparator (Sections 9.2.2, 10.3, and Chapter 12)
- Locator (Section 9.5)
- Template method (2.3.3, 10.5.1, and 11.2.1)
- Composition (Sections 2.5.2, 2.6, and 9.2.1)
- Adapter (Section 6.1.3)
- Position (Sections 7.3, 8.1.2, and 14.7.3)
- Iterator (Section 7.4)
- Factory Method (Sections 8.3.1 and 11.2.1)
- Comparator (Sections 9.2.2, 10.3, and Chapter 12)
- Locator (Section 9.5)
## 2.2 Inheritance
- inheritance allows subclasses whose functionality is a subset of their super class's to use the supper class's code as a starting point without having to re-type it.
- __is a relationship__: When a sub class's functionality is a subset of a super class's, the sub class *is a* super class.
- subclass is aka child class
- super-class is aka base class, or parent class
- *Is a* relationships tend to organize themselves in a hierarchical manner.
- the taxonomic rank is a perfect example of this, but there are many more.
- After inheriting, the subclass should (but doesn't have to) differentiate itself from its superclass by:
- *Augmenting* the superclass by adding new fields and methods
- *specialize* the superclass by providing new implementations that *override* existing methods
### 2.2.1 Extending the CreditCard Class
- UML diagrams show inheritance with a hollow arrow pointing from the subclass to the super-class
- inheritance syntax: __public class__ *SubClassName* __extends__ *SuperClassName*
- Java only allows *single inheritance*, meaning a child class can only inherit from one parent class
- Subclasses don't implicitly inherit their super-class's constructor. To explicitly call a superclass's constructor use the keyword __super__(*params*) at the first line of your constructor.
- __super__ is similar to the keyword __this__(*params*), but __this__ calls another constructor inside the subclass.
- If no call to super is made in your constructor, an implicit call to the default constructor, __super__(), will be made.
### 2.2.2 Polymorphism and Dynamic Dispatch
- __Liskov Substitution Principle__: a variable (or parameter) with a declared type can be assigned an instance from any direct or indirect subclass of that type.
- When we can assign an object of a subclass to a variable of a superclass, the superclass variable is said to be __*polymorphic*__.
- Java uses *dynamic dispatch* on polymorphic variables to use the properties (methods) most specific to the subclass.
- Java provides the __instance of__ method to determine the actual class of polymorphic variables.
### 2.2.3 Inheritance Hierarchies
- They have a long example of extending ArithmeticProgression, GeometricProgression and FibonacciProgression all from a base class, Progression. It was interesting.
## 2.3 Interfaces and Abstract Classes
- __Application Programming Interfaces__ (APIs) (aka interfaces) define the functionality a class presents to other objects.
- This book follows the [ADT](#Abstraction) approach to data structures where interfaces define ADTs and are specified as a type definition and a collection of methods (with arguments of specified type) for the interface.
- The compiler forces arguments passed to interface methods to be of the specified type. This is known as *strong typing*. Strong typing provides encapsulation and can help you catch errors.
### 2.3.1 Interfaces in Java
- In java, an __interface__ is a collection of method declarations (signatures) with no data and no bodies.
- An interface can't be directly instantiated. Interfaces are used through Non-abstract classes that implement the interface.
- When a class implements an interface, it must implement all the methods declared in the interface.
- Classes can implement multiple interfaces (but only one class).
### 2.3.2 Multiple Inheritance for Interfaces
-
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment