Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.

Slides:



Advertisements
Similar presentations
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Inheritance and Polymorphism.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Classes and Object- Oriented Programming.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter3: Introduction to Classes and Objects 1.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 13: Object-Oriented Programming
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
C++ fundamentals.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Chapter 6: A First Look at Classes
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Microsoft Visual Basic 2005: Reloaded Second Edition
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
Introduction to Object-oriented programming and software development Lecture 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 8 More Object Concepts
Writing Classes (Chapter 4)
An Object-Oriented Approach to Programming Logic and Design
Starting Out With Java 5 (Control Structures to Objects) Chapter 6 By Tony Gaddis Copyright © 2005 Pearson Addison-Wesley. All rights reserved.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: From Control Structures through Objects Third Edition.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 13 (Online): Object-Oriented Data Modeling Modern Database Management 10 th Edition.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
1.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
© 2010 Pearson Addison-Wesley. All rights reserved. 6-1 Chapter Topics Chapter 6 discusses the following main topics: –Classes and Objects –Instance Fields.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved. Chapter 6 Slide.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Chapter 2 Principles of Programming and Software Engineering.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
Inheritance and Polymorphism
Programming Logic and Design Seventh Edition
Topics Procedural and Object-Oriented Programming Classes
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
Corresponds with Chapter 7
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Presentation transcript:

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis Chapter 14: Object-Oriented Programming

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 14-2 Chapter Topics 14.1 Procedural and Object-Oriented Programming 14.2 Classes 14.3 Using the Unified Modeling Language to Design Classes 14.4 Inheritance 14.5 Polymorphism

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming Procedural Programming An early method of coding where programs are centered on the procedures or actions that take place in a program A procedure is simply a module As program get larger and more complex, this method leads to problems The procedures in a program written in a procedural language are in a preset order. The program moves from procedure to procedure typically without user interaction. Object Oriented Programming A newer method of coding where programs are centered on creating objects An object is a software entity that contains both data and procedures The data in a object is known as the object’s fields (variables, arrays…) The procedures that are performed are called methods

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming Object Oriented Programming (OOP) addresses the procedural problem of code/data separation by using two methods –Encapsulation – refers to the combining of data and code into a single object –Data hiding – refers to an object’s ability to hide its data from code that is outside the object Another OOP benefit is Object Reusability –For example, an object that renders 3D images can be used in many different programs

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes A class is code that specifies the fields and methods for a particular type of object –A class is coded and contains methods and fields Think of it like a blueprint, such as a blueprint for a house It’s a detailed description –An object is then created from the class It is an instance of a class Think of it as the actual house (For example, a button on a form belongs to a ‘button class’ in the particular language used to create the button. Every time a button is needed by the programmer, an ‘instance of the button is created’)

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes Creating a class Class ClassName Field declarations and method declarations End Class –The first line starts with Class, followed by the name of the class The programmer names the class following the same rules as naming variables –The field declarations (variables) and methods are defined within the class (Note: Take a look a Visual Basic form: see a class with its properties and methods. Ex. Text Box -> focus method)

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes Access specifiers –Private allows class members to be hidden from code outside the class –Public allows for all parts of the code to access the class members –It is common practice to make all fields private and to provide access only to those field through methods –Therefore, the methods should be public

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes Continued…

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes Inside Class Listing 14-3 –The field are defined as private to ensure data hiding –The methods are public so they can be accessed by main –When the set modules are called, a String is passed into the method as an argument and that value is set to the private field –When the get modules are called, they simply return the value of the private field

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes Inside Program 14-1 –An variable is created myPhone –myPhone is then used with the keyword New to create the object in memory –Values are then stored in the object’s field by calling the class methods Call myPhone.setManufacturer(“Motorola”) –Values are then displayed by calling the class methods Display “The manufacturer is “, myPhone.getManufacturer( ) –The dot notation is used to associate an object with a member of the class

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes Constructor is a method that is automatically called when an object is created –The purpose is to initialize an object’s fields with starting values –A programmer can write their own constructor to initialize fields –Or they can use the default constructor that is available with most programming languages

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using the Unified Modeling Language to Design Classes The Unified Modeling Language (UML) is a standard way of drawing diagrams that describe object-oriented systems –Contains a set of standard diagrams for graphically depicting OO systems Figure General layout of a UML diagram for a class

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using the Unified Modeling Language to Design Classes Data type, method parameter, and access specification notation is also added to a UML diagram –The data type specifies the data type of the field or the data type of the method –The method parameter specifies the parameter variables and their data types –The access specification indicates a + for public or a – for private

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using the Unified Modeling Language to Design Classes Figure UML diagram for the CellPhone class with access specification notation

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Inheritance Inheritance allows a new class to extend an existing class, whereas the new class inherits the members of the class it extends –The superclass is the base class –The subclass(es) is the derived class Figure Bumblebees and grasshoppers are specialized versions of an insect

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Polymorphism Polymorphism allows you to create methods with the same name in different classes (that are related through inheritance –The programmer has the ability to call the correct method depending on the type of object that is used to call it –Polymorphism refers to an object’s ability to take different forms

Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley #Program 14 ‐ 1 class CellPhone: def set_manufacturer(self, manufact): self.__manufacturer = manufact def set_model_number(self, model): self.__model_number = model def set_retail_price(self, retail): self.__retail_price = retail def get_manufacturer(self): return self.__manufacturer def get_model_number(self): return self.__model_number def get_retail_price(self): return self.__retail_price def main(): # Create a CellPhone object. The phone # variable will reference the object. phone = CellPhone() # Store values in the object's fields. phone.set_manufacturer("Motorola") phone.set_model_number("M1000") phone.set_retail_price(199.99) # Display the values stored in the fields. print 'The manufacturer is', phone.get_manufacturer() print 'The model number is', phone.get_model_number() print 'The retail price is', phone.get_retail_price() # Call the main function. main()