Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Object-Oriented Thought Process, Chapter 1

Similar presentations


Presentation on theme: "The Object-Oriented Thought Process, Chapter 1"— Presentation transcript:

1 The Object-Oriented Thought Process, Chapter 1
Introduction to Object-Oriented Concepts The Object-Oriented Thought Process, Chapter 1

2 Outline Course overview Getting to know you
History of programming paradigms Introduction to Object Oriented Programming (OOP) Classes & Objects Encapsulation Inheritance Polymorphism Composition

3 Getting to Know You Name Background Where from Programming background
The Man without a Face, oil on panel, 11x14, 2005 – Dae-Woong Nam Name Background Where from Programming background Languages Software development experience

4 Solving Problems With The Aid of Computers
Communication? Programming language Machine language Address Machine Instruction   1   2   3   4  

5 Assembly Instructions
Solving Problems With The Aid of Computers Communication? Programming language Machine language Assembly Instructions push cs pop ds mov ah, 9 int 21h sloop:

6 Procedural Programming language
Solving Problems With The Aid of Computers Communication? Procedural Programming language Machine language High-level Program for(int i=0; i<10; i++) System.out.println(list[i]);

7 Procedural Programming
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include<stdio.h> // function prototype, also called function declaration float square ( float x );                               // main function, program starts from here int main( )               {     float m, n ;     printf ( "\nEnter some number for finding square \n");     scanf ( "%f", &m ) ;     // function call     n = square ( m ) ;                           printf ( "\nSquare of the given number %f is %f",m,n ); } float square ( float x )   // function definition     float p ;     p = x * x ;     return ( p ) ;

8 Structure of a Procedural Program
Procedural Programming Structure of a Procedural Program function-1() main() In procedural programming a program consists of a set of functions. The first function to be executed is often called ‘main’.

9 Evolution of Programming
The early decades (40s – 60s) Main focus of attention - computer hardware. Building faster, simpler, and, more efficient machines. Problems, problems, problems,…... ENIAC I

10 Rising software complexity!
Systemic Problems Inability to predict time, effort, and costs. Inability to deliver quality software. Lack of enough competent software developers Rising software complexity! Large software systems: 4 x 106 – 100 x 106

11 Dimensions of Software Complexity
Algorithmic Functional Structure of the data Structure of the program How the program communicates etc.

12 Solution? Current code-centric development practices are inadequate.
Need to take an engineering approach to developing software! Includes understanding the process used to develop and evolve software.

13 The Software Lifecycle
Requirements Analysis Software Design Implementation Testing Deployment Evolution What are the most difficult phases of the software process?

14 The Software Lifecycle
Requirements Analysis Software Design Implementation Testing Deployment Evolution Software design is arguably the most difficult phase of development.

15 Managing Complexity Design! Design! Design!
Make engineering is a Model-Driven Discipline! Address the weakness of OOP Difficulty reusing code Accidental complexity Wide semantic gap between the real world and the software world

16 Object Oriented Programming
In machine language programming – programs are sequences of bits. In assembly language programming – programs are pieces of code. In procedural programming – programs are collections of interacting procedures/functions. In OOP – programs are collections of interacting objects.

17 Implementation: From Concept to Language
In Procedural Programming procedures are modeled as: subroutines, procedures and functions in the software world. A program is a set of interacting functions. In OOP objects in the real world are modeled as: classes and objects in software world. A program is a collection of classes and interacting objects.

18 Bank Client StockBroker Motivating Example
In OOP objects in the real world are modeled as: classes and objects in software world. A program is a collection of classes and interacting objects.

19 Requirements Analysis
Motivating Example Let us design the UML class diagram by hand Requirements Analysis Software Design Implementation Testing Deployment Evolution

20 Fundamental Concepts of OOP
Class/Object Encapsulation Inheritance Polymorphism Composition

21 OOP Concepts: Classes & Objects
In OOP objects in the real world are modeled as: classes and objects in software world. A program is a collection of classes and interacting objects. Every object oriented programming language must not only have a way to define functions – they must also allow classes and objects to be defined.

22 OOP Concepts: Classes & Objects
class = data + methods class global data G function-1() main() Procedural Program global data G function-1() main()

23 Example of a Java Class public class Account { private String accName;
private int accNumber; private double balance; public boolean deposit(double amount){ if(amount > 0){ this.balance += amount; return true; } return false; public boolean withdraw(double amount){ if(this.balance >= amount){ this.balance -= amount; }//end of class

24 Example of a Java Class public class Account implements IAccount {
private String accName; private int accNumber; private double balance; public boolean deposit(double amount){ if(amount > 0){ this.balance += amount; return true; } return false; public boolean withdraw(double amount){ if(this.balance >= amount){ this.balance -= amount; }//end of class

25 OOP Concepts: Classes & Objects
In procedural programming: Functions are black boxes. all a user needs to know to effectively use a method is the method signature: The name of the method The parameters passed to the method The return type of the method

26 OOP Concepts: Classes & Objects
In procedural programming: Functions are black boxes. all a user needs to know to effectively use a method is the method signature: The name of the method The parameters passed to the method The return type of the method In OOP: Classes and functions are black boxes. all a user needs to know to effectively use a class is the class interface: The lass interface includes a list of method signatures

27 Method Signatures The following is all the user needs to know to effectively use the methods: The name of the method The parameters passed to the method The return type of the method

28 O-O Programming The fundamental advantage of O-O programming is that the data and the operations that manipulate the data are both contained in the object. For example, when an object is transported across a network, the entire object, including the data and behavior, goes with it.

29 Object Data The data stored within an object represents the state of the object. In O-O programming terminology, this data is called attributes. Eg. 1: UML account class with account number, balance. E.g. 2: Java account class with account number, balance.

30 Object Behavior In O-O programming terminology object behaviors are contained in methods, and you invoke a method by sending a message to it. E.g. 1: UML account class with methods: deposit, withdraw, getBalance, setBalance. E.g. 2: Java account class with methods: deposit, withdraw, getBalance, setBalance.

31 What Exactly Is a Class? A class is a blueprint for an object.
The process of creating an object from a class is called instantiation. When you instantiate an object, you use a class as the basis for how the object is built. NB: primitive types vs classes.

32 Higher Level Data Types?
A class can be thought of as a sort of higher-level data type. For example, just as you create an integer or a float: int x; float y; Integers and floats are built-in types Classes are user-defined types.

33 What Exactly Is a Class? An object cannot be instantiated without a class. Classes can be thought of as the templates, or cookie cutters, for objects as seen in the next figure.

34 Modeling a Class in UML

35 Program Spaces

36 Fundamental Concepts of OOP
Class/Object Encapsulation Inheritance Polymorphism Composition

37 Encapsulation One of the primary advantages of using objects is that the object need not reveal all its attributes and behaviors. In good O-O design (at least what is generally accepted as good), an object should only reveal the interfaces needed to interact with it.

38 Encapsulation Details not pertinent to the use of the object should be hidden from other objects. This is called encapsulation.

39 Interfaces Any behavior that the object provides must be invoked by a message sent using one of the provided interfaces. The interface should completely describe how users of the class interact with the class. methods that are part of the interface are designated as public.

40 Interfaces Interfaces do not normally include attributes only methods.
As discussed earlier in this module, if a user needs access to an attribute, then a method is created to return the attribute.

41 Implementations Only the public attributes and methods are considered the interface. The user should not see any part of the implementation interacting with an object solely through interfaces. In previous example, for instance the Employee class, only the attributes were hidden. Thus, the implementation can change and it will not affect the user's code.

42 Fundamental Concepts of OOP
Class/Object Encapsulation Inheritance Polymorphism Composition

43 Inheritance Inheritance allows a class to inherit the attributes and methods of another class. This allows you to create brand new classes by abstracting out common attributes and behaviors.

44 Mammal Hierarchy

45 Mammal Hierarchy

46 Superclasses and Subclasses
The superclass, or parent class, contains all the attributes and behaviors that are common to classes that inherit from it.

47 Superclasses and Subclasses
A shape hierarchy

48 Fundamental Concepts of OOP
Class/Object Encapsulation Inheritance Polymorphism Composition

49 Polymorphism Polymorphism means many forms. Java provides two forms of polymorphism: Method overloading Operator overloading.

50 Fundamental Concepts of OOP
Class/Object Encapsulation Inheritance Polymorphism Composition

51 Composition It is natural to think of objects as containing other objects. A television set contains a tuner and video display.

52 Composition A computer contains video cards, keyboards, and drives.
Although the computer can be considered an object unto itself, the drive is also considered a valid object.

53 Composition In fact, you could open up the computer and remove the drive and hold it in your hand. Both the computer and the drive are considered objects. It is just that the computer contains other objects such as drives. In this way, objects are often built, or composed, from other objects: This is composition.

54 Has-a Relationships While an inheritance relationship is considered an Is-a relationship for reasons already discussed, a composition relationship is termed a Has-a relationship.

55 Has-a Relationships Using the example in the previous section, a television Has-a a tuner and Has-a video display. A television is obviously not a tuner, so there is no inheritance relationship.

56 Has-a Relationships In the same vein, a computer Has-a video card, Has-a keyboard, and Has-a disk drive. The topics of inheritance, composition and how they relate to each other is covered in great detail later in the course.

57 How Java Works See

58 Qu es ti ons? The End ______________________ Devon M. Simmonds
Computer Science Department University of North Carolina Wilmington _____________________________________________________________


Download ppt "The Object-Oriented Thought Process, Chapter 1"

Similar presentations


Ads by Google