1 Chapter 1 Object-Oriented Programming. 2 OO programming and design Object-oriented programming and design can be contrasted with alternative programming.

Slides:



Advertisements
Similar presentations
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
Classes & Objects Computer Science I Last updated 9/30/10.
Introduction To System Analysis and Design
UML – Class Diagrams.
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 10 Object-Oriented Modeling.
1 CS1001 Lecture Overview Homework 3 Homework 3 Project/Paper Project/Paper Object Oriented Design Object Oriented Design.
Object Oriented System Development with VB .NET
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Chapter 1 Principles of Programming and Software Engineering.
1 Object-Oriented Design. 2 Objectives F To become familiar with the process of program development. F To the relationship types: association, aggregation,
1 CS1001 Lecture Overview Object Oriented Design Object Oriented Design.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Chapter 13: Object-Oriented Programming
Chapter 10 Classes Continued
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Introduction To System Analysis and design
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
© 2008 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 8: More About OOP and GUIs.
An Object-Oriented Approach to Programming Logic and Design
Chapter 3 Introduction to Collections – Stacks Modified
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Introduction To System Analysis and Design
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Learners Support Publications Object Oriented Programming.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Object-Oriented Programming Chapter Chapter
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Chapter 2 Principles of Programming and Software Engineering.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Principles of Programming & Software Engineering
Object-Oriented Programming Concepts
The Movement To Objects
Chapter 11 Object-Oriented Design
Principles of Programming and Software Engineering
Introduction to Data Structure
Presentation transcript:

1 Chapter 1 Object-Oriented Programming

2 OO programming and design Object-oriented programming and design can be contrasted with alternative programming approaches and associated design techniques. For example, object-oriented programming and design can be contrasted with procedural programming and top-down functional decomposition design.

3 OO programming and design The contrast between object-oriented programming and alternatives such as procedural programming can be highlighted by focusing on program modules. A module is a program component that can be designed, coded, translated, and tested independently and then incorporated into a larger program.

4 Modules Modules in procedural languages such as C are procedures, e.g., the C function int find_max( int n1, int n2 ) { if ( n1 > n2 ) return n1; if ( n1 > n2 ) return n1; else return n2; else return n2; }

5 Modules Modules in object-oriented languages such as Java are classes, which encapsulate or contain storage variables and procedures. –For example, Java has a String class that encapsulates storage for the characters in a string together with procedures for constructing a string, determining a string’s length, checking whether a string contains a given character, and so on.

6 Top-down design Procedural programming is associated with a design technique known as top-down design or top-down functional decomposition. In top-down design, a problem is decomposed into subproblems. The problem and its subproblems are then assigned to procedures for solution.

7 Top-down design –For example, the problem of building a car might be decomposed into the subproblems of first building the chassis, the engine, the drivetrain, and so on and then of assembling the prebuilt parts. The overall problem of building the car could be assigned, in a simulation, to a main procedure, which in turn would invoke subprocedures such as build_chassis to handle the subproblems.

8 Top-down design Top-down design and the associated procedural programming have drawbacks, particularly with respect to software maintenance. For example, a change in problem decomposition entails a change in procedural decomposition, which can ripple through an entire decomposition hierarchy. This is known as cascading changes.

9 Top-down design –For instance, suppose that the main procedure (which handles the main problem of building a car) needs to be changed by, for example, passing a new argument to subprocedures such as build_chassis, which in turn need to pass the new argument to their subprocedures, and so on until the change in main has rippled throughout the decomposition hierarchy.

10 OO design and programming Object-oriented design and programming attempt to overcome shortcomings such as cascading changes. In an object-oriented approach, classes behave as modules that can interact with other modules in such a way that a change to one does not require a change to all of the others.

11 Two senses of class Class has two distinct but related senses: –In object-oriented design, a class is a collection of objects such as humans that share features or properties (e.g., humans are warm-blooded and risible) and behaviors or operations (e.g., humans gather, hunt, cook, and even tango). A class Human could represent humans in an object-oriented design.

12 Class as data type –In object-oriented programming, a class is a data type that can have instances. For example, Java has a String class that is a standard data type in the language. Particular strings such as “Mary Leakey” would be represented in Java as String instances or objects. A programmer- defined class such as Human might be introduced as a data type to represent humans.

13 Class as data type –The classes of object-oriented design can be represented in an object-oriented language as class data types. –Class data types encapsulate variables to represent class features (e.g., a variable footCount might be initialized to 2) and procedures to represent operations (e.g., a procedure might show a video of two humans doing the tango).

14 Class and encapsulation The class as a data type can encapsulate –variables or fields, which represent features or properties that class instances share –procedures Procedures used to create or construct instances of a class are known as constructors. Procedures that represent class operations or behaviors are know as methods.

15 Class members Fields are encapsulated variables, including arrays or other aggregates. Constructors are encapsulated procedures used to construct class instances. –In Java, the code segment new String() uses the operator new and the String() constructor to construct a string.

16 Methods Methods are encapsulated procedures that provide class operations. –In Java, the code segment String s = new String( “hi” ); int len = s.length(); first constructs a string and then invokes the encapsulated length method to determine the number of characters in the string.

17 “Class” and “instance” members The class data types in object-oriented languages have two types of members: –Members associated with the class are “class members.” For example, an Emp class might have a “class member” named count to track how many Emp instances have been constructed.

18 “Class” and “instance” members –Members associated with class instances are “instance members.” For example, an Emp class might have a name “instance member” to represent each Emp loyee’s name. –In Java, members marked as static are “class members,” whereas members not marked as static are “instance members.”

19 “Class” and “instance” members –The Java code segment class Emp { static int count; String name; } illustrates the syntax. The field count is a “class member,” whereas the field name is an “instance member.”

20 Class and abstract data type The class construct in object-oriented languages directly supports abstract data types—data types defined by high-level operations rather than by low-level implementation details. Use of abstract data rather than primitive data types eases programming tasks.

21 Stack as an abstract data type A Stack is an example of an abstract data type. A Stack is a list with insertions and deletions done at the same end, known as the top. Its high-level operations include –push, which inserts an item onto the Stack. –pop, which removes the Stack’s top item. –peek, which shows the Stack’s top item without removing it.

22 Stack class A Stack class type would encapsulate methods such as push, pop, and peek to represent high-level Stack operations.Other methods such as isEmpty and isFull could be included to test whether a Stack is empty or full. Constructors would be provided to construct Stack instances.

23 Information hiding An abstract data type exposes to clients a high-level interface that specifies the type’s behavior. –In the Stack example, the interface consists of methods such as push and pop that specify high-level operations on a Stack. An abstract data type hides from clients the type’s low-level, implementation details.

24 Information hiding In object-oriented languages, a class is a type that supports information hiding. –Class members such as high-level methods can be declared public to expose such methods to clients. –Class members that provide implementation detail can be declared private to hide such details from clients.

25 Information hiding By directly supporting information hiding, a class in an object-oriented language is well suited for delivering abstract data types. –The Java String class is, in effect, an implementation of a string as an abstract data type.

26 Client/server model and OO Object-oriented programming is based on a client/server model of computing –A class and its instances (objects) are servers that provide services to clients. –An application that uses a class and its instances are clients. –For instance, the Java String class provides string-processing services to client applications.

27 Message passing In the client/server model, invoking a class or instance method sends a message that requests a service. –For instance, the code segment String s = “Hi, world!”; int n = s.length(); requests the length of the string to which s refers.

28 Inheritance Object-oriented languages support inheritance hierarchies, which are parent/child relationships between classes. –For instance, a Window class might have DialogWindow as a subtype. In this case, the Window class is the parent class and the DialogWindow class is the child class.

29 Inheritance Inheritance provides a basic form of code reuse in that a child class inherits parent class members, including the methods. Some object-oriented languages (e.g., C++) allow a child class to have multiple parent classes. In Java, by contrast, every class except Object has exactly one parent.

30 Inheritance Languages such as C++ thus support multiple inheritance for classes, whereas languages such as Java support only single inheritance for classes. Designing inheritance hierarchies is a critical part of object-oriented design.

31 Polymorphism Polymorphism is a powerful object-oriented construct in which distinct methods within an inheritance hierarchy can be invoked with the same syntax. –For instance, assume an inheritance hierarchy of window classes in each class has its own appropriate implementation of a show method, which shows the window on the screen.

32 Polymorphism –Regardless of whether win refers to, say, a MenuWindow or a MessageWindow, the statement win.show(); // show yourself displays the window. At run time, the systems determines the type of window to which win refers and invokes the show method encapsulated in that type.

33 Polymorphism A method such as show is a polymorphic method; that is, a method invoked with the same syntax as other polymorphic methods in the same inheritance hierarchy. Polymorphism is used widely in object- oriented programming because of its power, flexibility, and convenience.

34 Component-based programming Modern object-oriented programs tend to be component-based. A component is a prebuilt part or module that can be integrated with other such parts to build or extend an application. A container is a special-purpose component that can hold or embed other components.

35 Component-based programming Programs with graphical user interfaces are commonly component-based. For example, the user interface might consist of a framed window (container) that holds components such as buttons, lists, checkboxes, menus, and the like. Component-based programming is not restricted to GUIs, however.

36 Component-based programming To be easily usable, a component should be designed under object-oriented principles: –The component should expose to clients only high-level functionality. –The component should hide from clients the low-level implementation details that support its high-level functionality.

37 UML The Unified Modeling Language (UML) facilitates the design, development, deployment, and maintenance of software systems. UML has become the modeling language of choice for object-oriented design. UML is graphical, expressive, and concise.

38 UML Basic UML vocabulary consists of –Things: Entities to be modeled, whether concrete or abstract. –Relationships: Connections among things. –Diagrams: graphical depictions of things and their relationships

39 UML diagram 1 * University Academic Department

40 UML diagram The diagram on the previous slide expresses that a university is a collection of arbitrarily many academic departments, each of which is associated with exactly one university. UML diagrams can serve as high-level design specifications for software systems and, in this role, can guide code development.