Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
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 structure
Example: to go From point A to point B
Non 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) Object
   Can be real-world objects: this desk, this ballpen,etc
   Can represent GUI (Graphical User Interface) components
   Can 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 objects
example: HondaAccordCar, Boeing747Airplane
Relation between Object and Class

     Object             Class

     has identity, a    a blueprint or
     unique instance of factory that holds
     a Class            or produce the
                        objects

     dynamic,           static structure
     generated in       written by
     runtime            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 viewer
 Encapsulation: detail or implementation hidden so that
 only interface exposed
 Polymorphism: 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 change
OCP-open-close: class should be open to extension, close to
modification
LSP- 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

More Related Content

Object oriented fundamentals_in_java

  • 1. Object-Oriented Programming Fundamentals in Java by George Wang
  • 2. 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
  • 3. What is Object-Oriented Programming? "Object oriented" means that we organize software as a collection of discrete objects that have both data and structure Example: to go From point A to point B Non OO: Drive(200 miles) (just do it) OO: myCar =new HondaAccord(); myCar.drive(200miles)
  • 4. What is Object-Oriented Programming - continued
  • 5. Why Object-Oriented Programming? Software Development is inherently a complex process. from OO Analysis and Design by Grady Booch, 2nd Edition
  • 6. What is Object? 1) Object: eveything in the world is an object - concrete or conceptual. It is an instance of a Class 2) Object Can be real-world objects: this desk, this ballpen,etc Can represent GUI (Graphical User Interface) components Can 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???
  • 7. What is Class? a factory or blueprint that define a similar type or group of objects example: HondaAccordCar, Boeing747Airplane
  • 8. Relation between Object and Class Object Class has identity, a a blueprint or unique instance of factory that holds a Class or produce the objects dynamic, static structure generated in written by runtime programmers
  • 9. 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){ ... } }
  • 10. Usage example public class CarUsageExample{ public static void main(Strings args[]){ HondaAccord myBlueHonda= new HondaAccord(Color.blue); myBlueHonda.drive(200); //go 200 miles } }
  • 11. Characteristics of OO Programming Abstraction: focus on the essential characteristics of an object that distinguish it from others, relative to the perspective of the viewer Encapsulation: detail or implementation hidden so that only interface exposed Polymorphism: same function name can have different behavior depending on its subtype (airplane.travel() vs car. travel()) Inheritance: is-a relationship
  • 12. OO design principles SRP- single responsibility (high cohesion): a class should have one reason to change OCP-open-close: class should be open to extension, close to modification LSP- 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