object oriented fundamentals_in_java
DESCRIPTION
TRANSCRIPT
Object-Oriented Programming Fundamentals in Java
by George Wang
Objectives
Definition of Object Oriented, Object, Class and relationship between Object and Class
General structure of a Class
How Objects are created and used
Characteristics of Object Oriented Programming
What is Object-Oriented Programming?
"Object oriented" means that we organize software as a collection of discrete objects that have both data and structureExample: to go From point A to point BNon OO: Drive(200 miles) (just do it)OO: myCar =new HondaAccord(); myCar.drive(200miles)
What is Object-Oriented Programming -continued
Why Object-Oriented Programming?
Software Development is inherently a complex process.
from OO Analysis and Design by Grady Booch, 2nd Edition
What is Object?
1) Object: eveything in the world is an object - concrete or conceptual. It is an instance of a Class
2) ObjectCan be real-world objects: this desk, this ballpen,etcCan represent GUI (Graphical User Interface) componentsCan represent software entities (events, files, images, etc.)Can represent abstract concepts (for example, rules of a game, a particular type of dance, etc.)
---Ask students: can anyone give an example of some Objects???
What is Class?
a factory or blueprint that define a similar type or group of objectsexample: HondaAccordCar, Boeing747Airplane
Relation between Object and Class
Object Class
has identity, a unique instance of a Class
a blueprint or factory that holds or produce the objects
dynamic, generated in runtime
static structure written by programmers
a Class Example
import java.awt.color;public class HondaAccord {
private Color carColor; public HondaAccord(Color carColor){ this.carColor= carColor; }
public void Drive(int miles){ ... }}
Usage example
public class CarUsageExample{
public static void main(Strings args[]){ HondaAccord myBlueHonda= new HondaAccord(Color.blue); myBlueHonda.drive(200); //go 200 miles }}
Characteristics of OO Programming
Abstraction: focus on the essential characteristics of an object that distinguish it from others, relative to the perspective of the viewerEncapsulation: detail or implementation hidden so that only interface exposedPolymorphism: same function name can have different behavior depending on its subtype (airplane.travel() vs car.travel())Inheritance: is-a relationship
OO design principles
SRP- single responsibility (high cohesion): a class should have one reason to changeOCP-open-close: class should be open to extension, close to modificationLSP- Liskov substitution: subtype is-a basetype, therefore can substitute for it.DIP - dependency inversion: code to (depend to) interface (high level modules should not depend on low level modules)ISP-interface segregation principle: when there is incohesion, separate them into different interfaces
-from Agile Software Development by Robert Martin