object oriented fundamentals_in_java

12
Object-Oriented Programming Fundamentals in Java by George Wang

Upload: self

Post on 17-Jan-2015

545 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Object oriented fundamentals_in_java

Object-Oriented Programming Fundamentals in Java

by George Wang

Page 2: Object oriented fundamentals_in_java

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

Page 3: Object oriented fundamentals_in_java

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)

Page 4: Object oriented fundamentals_in_java

What is Object-Oriented Programming -continued

Page 5: Object oriented fundamentals_in_java

Why Object-Oriented Programming?

Software Development is inherently a complex process.

from OO Analysis and Design by Grady Booch, 2nd Edition

Page 6: Object oriented fundamentals_in_java

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???

Page 7: Object oriented fundamentals_in_java

What is Class?

a factory or blueprint that define a similar type or group of objectsexample: HondaAccordCar, Boeing747Airplane

Page 8: Object oriented fundamentals_in_java

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

Page 9: Object oriented fundamentals_in_java

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){ ... }}

Page 10: Object oriented fundamentals_in_java

Usage example

public class CarUsageExample{

public static void main(Strings args[]){ HondaAccord myBlueHonda= new HondaAccord(Color.blue); myBlueHonda.drive(200); //go 200 miles }}

Page 11: Object oriented fundamentals_in_java

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

Page 12: Object oriented fundamentals_in_java

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