Top Banner
1 Introduction to Object Orientation (OO) & Related Terminology In a non-programming specific way, orient ourselves to the principles and related terminology to OO development Identify KEY OO Terms
65

1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

Mar 26, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

1

Introduction to Object Orientation (OO) &

Related Terminology

In a non-programming specific way, orient ourselves to the principles and related terminology to OO development

Identify KEY OO Terms

Page 2: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

2

GOALS...

TO understand prevailing methodology & related principles

To match relevant programming terminology to OO principles

Page 3: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

3

Development in VB:

Given a problemStarted CodingAsked Questions on What

you were Supposed to do !!!Made Major changes to your

programsSome testing...

Page 4: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

4

...Development in VB:

Asked for me to Grade itWhite Elephant(Major) modificationsFinally Done !!!

Page 5: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

5

...Development in VB:

Then, the Next project followed the same paradigm with little reuse of prior code

Page 6: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

6

VB Terms:

Variables

Events

Subroutines

Page 7: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

7

Development in Java:

Remember how I required you to code the File I/O projects ?

Structures Separate code module

routines to open, read and write File I/O

Display data on a form To/From Structures

Page 8: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

8

Development in Java:

In General, we separated the Display (GUI) from the Data Gathering from the Data

Modifications

Page 9: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

9

Development in Java:

Furthermore, In the Code Modules we attempted to Separate the processing from the Displaying as the Code Modules should make NO reference to the controls on the form

(textboxes, labels, etc)

Page 10: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

10

Development in Java:

In theory, we could have taken your Code module and used it for other programs without:

Knowing or Caring how the data was processed, modified or Displayed

Page 11: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

11

Now in Java we WILL…

Given a problem

UNDERSTAND the problem

Break the problem up into manageable pieces

Page 12: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

12

Now in Java we WILL…

Identify the relevant functions that each piece needs to perform

Create the variables necessary to maintain the STATE of each “piece”

Page 13: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

13

Now in Java we WILL…

Identify how each “piece” will communicate

Develop the main program driver that will control the process (except for event drivenProjects)

Page 14: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

14

Now in Java we WILL…

Test, debug and modify

Asked for me to Grade it

Done !!!

Page 15: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

15

Java Terms:

Attributes

Events

Methods

Page 16: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

16

In our File I/O project, we can write the following methods:

Open a file Process a file Update a file Close a file

Page 17: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

17

In our File I/O project, we can write the following methods:

Read data from the user (console)

Send data to the user (console)

These methods will be able to be reused for any other project that requires Retrieving / Sending data

Page 18: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

18

Old School Development:

Set up separate phone lines FOR EACH person you wish to talk to

Wasteful

Repeats 99 percent of the same functionality

Page 19: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

19

OO Development:

Develop classes that handle the different parts of a GENERIC phone communication process

(identify who to call, place a call, engage in conversation, end the call)

Page 20: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

20

OO Development:

Set up 1 general use phone line that can handle multiple INSTANCES of phone calls to anyone who has a phone

Creates useful and extensible components

Page 21: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

21

OO Development:

Reuses a generic communication protocol and instantiates it with a STATE based on the person you wish to talk to (phone number, etc)

Page 22: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

22

TPS: PERSON

Think of a generic “person” blueprint and answer the following questions:

Page 23: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

23

What ATTRIBUTES (properties) apply to the Person Blueprint ?

Page 24: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

24

What ATTRIBUTES (properties) apply to the Person Blueprint ?

HairVoiceSizeSkin ToneGenderRaceSSNAGE

Page 25: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

25

What BEHAVIORS (methods) apply to the Person Blueprint ?

Page 26: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

26

What BEHAVIORS (methods) apply to the Person Blueprint ?

Change Hair ColorChange SizeChange Gender

Page 27: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

27

What if we disallow or encapsulate the ability for ANY user of the Person Blueprint from altering hair color ?

Page 28: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

28

How can we use this blueprint to create other types of “Persons” ?

Teacher Person

Policeman Person

Male Person

Female Person

Page 29: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

29

How does the use of the Generic Person Blueprint assist us in creating these “instances” of the generic Person ?

Page 30: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

30

What about Attributes and Behaviors that are different in these instances ?

Page 31: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

31

Answers the SAME questions for:

A Generic Car Blueprint

Page 32: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

32

Answers the SAME questions for:

A Salary Calculation Application

Page 33: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

33

OOP

Page 34: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

34

We will use the LOAN class analogy

There can be many types of loans: car mortgage student

Page 35: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

35

OOP in a Nutshell:

A program models a world of interacting objects

Objects create other objects and “send messages” to each other (in Java, call each other’s methods)

Each object belongs to a class; a class defines properties of its objects

A class implements an ADT; the data type of an object is its class

Programmers write classes (and reuse existing classes)

Page 36: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

36

Abstraction

... relevant to the given project (with an eye to future reuse in similar projects).

Abstraction means ignoring irrelevant features, properties, or functions and emphasizing the relevant ones...

“Relevant” to what?

Page 37: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

37

Example:

In identifying the relevant elements in building a generic blueprint for handling various loans, you can ignore adding functionality that calculates the square of all natural numbers

Page 38: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

38

Encapsulation

Encapsulation means that all data members (fields) of a class are declared private. Some methods may be private, too.

The class interacts with other classes (called the clients of this class) only through the class’s constructors and public methods. Constructors and public methods of a class serve as the interface to class’s clients.

Page 39: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

39

Encapsulation

The Hiding or Shielding of some of the properties and or behaviors of the class from users of the class

Page 40: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

40

Encapsulation ensures that structural changes remain local

Changes in the code create software maintenance problems

Usually, the structure of a class (as defined by its fields) changes more often than the class’s constructors and methods

Encapsulation ensures that when fields change, no changes are needed in other classes (a principle known as “locality”)

Page 41: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

41

Example:

In building the loan class, you would hide an attribute that holds the Prime Interest Rate as well as any intermediate calculation attributes

Page 42: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

42

Example:

Encapsulation allows the class to restrict how the attributes can be modified

Page 43: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

43

True or False? Abstraction and encapsulation are helpful for the following:

Team development ________

Reusable software ________

GUI programming ________

Easier program maintenance ________

Page 44: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

44

Answer:

Team development ________

Reusable software ________

GUI programming ________

Easier program maintenance ________

T

T

T

(True if you are working on system packages, such as Swing)

F

Page 45: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

45

Inheritance

A class can extend another class, inheriting all its data members and methods while redefining some of them and/or adding its own.

Inheritance represents the is a relationship between data types. For example: a HomeLoan is a ;loan.

Page 46: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

46

Inheritance

The Use of a BASE or Blueprint class that contains the common properties and behaviors to create a subset of the class

Page 47: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

47

Example:

With our loan class, the calculation of the Interest Rate may be the same Regardless of the type of loan. So, you could design the Loan class so that...

Page 48: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

48

Example:

… It does the calculation and all of the loan types can inherit and USE thatCalculation.

Page 49: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

49

True or False? Inheritance is helpful for the following:

Team development ________

Reusable software ________

GUI programming ________

Easier program maintenance ________

Page 50: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

50

Answer:

Team development ________

Reusable software ________

GUI programming ________

Easier program maintenance ________

F

T

???

T

Page 51: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

51

Polymorphism

Polymorphism ensures that the appropriate method is called for an object of a specific type when the object is disguised as a more general type.

Good news: polymorphism is already supported in Java — all you have to do is use it properly.

Page 52: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

52

Polymorphism

The Use of a base class to serve as an interface to the use or implementation of ANY Derived Classes

Page 53: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

53

Called Dymanic Method Binding or Late Binding

You can create a generic blueprint class that performs methods commonto any class that inherits from it.

You only need to create a placeholder of the generic class and then fill it in as needed.

Page 54: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

54

Example:

With the car loan, we create the generic Loan class.

This Class performs the common methods and holds common attribute STATE

Page 55: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

55

Example:

We can create a placeholder of the Loan class and then fill it with the studentloan inherited version of the Loan class

And it will , by default, contain the same public methods as the Generic Loan class

Page 56: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

56

TPS:

Take one of the examples of Person, Car or Salary Calculation to create a SUPER BLUEPRINT that maintains attributes and behaviors that ARE COMMON regardless of the TYPE of Person, Car or Type of Salary being calculated (inheritance)

Page 57: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

57

TPS:

Using the previous example, what attributes or behaviors can be

Hidden ?

Page 58: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

58

Other Characteristics of OO

Divide and Conquer Principle

Interface Principle

Information Hiding Principle

Generality Principle

Page 59: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

59

Terms:

Inheritance

Encapsulation

Polymorphism

Page 60: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

60

Terms:

Class

Super Class

Sub / Inherited / Derrived Class

Page 61: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

61

Terms:

Interface

Abstract Class

Page 62: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

62

Terms:

Public

Private

Protected

Page 63: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

63

Terms:

Attributes

Methods

Extends

Page 64: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

64

Terms:

Override

Object

Page 65: 1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology.

65

TEST IS NEXT !!!