Classes and Objects housefly object Insect class mosquito object

Slides:



Advertisements
Similar presentations
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Advertisements

Chapter 6: A First Look at classes. Object-Oriented Programming  Object-oriented programming is centered on creating objects rather than procedures.
Basic OOP Concepts and Terms
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
Object Oriented Programming
Introduction to Classes, Objects, Methods and Attributes Lecture # 2.
Introduction to Object-oriented programming and software development Lecture 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: Early Objects Third Edition by Tony Gaddis Chapter.
Starting Out with Java: From Control Structures through Objects.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
: Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
© 2010 Pearson Addison-Wesley. All rights reserved. 6-1 Chapter Topics Chapter 6 discusses the following main topics: –Classes and Objects –Instance Fields.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Introduction to Classes, Objects, Methods and Attributes Lecture # 5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved. Chapter 6 Slide.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005 Pearson Addison- Wesley. All rights reserved. Chapter 1 Slide #1.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Introduction to Object-oriented Programming
Recursion Recursion is a fundamental programming technique that can provide an elegant solution certain kinds of problems © 2004 Pearson Addison-Wesley.
Advanced Java Topics Chapter 9
Chapter 3 Classes & Objects
Object Oriented Concepts -I
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
all loops initialization – set up the loop
Abstract Data Types and Encapsulation Concepts
Chapter 17 Linked Lists.
Chapter 19 Binary Search Trees.
11.7 Motion in Space Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 4 Inheritance.
Chapter 1 Preliminaries.
Chapter 14 Graphs and Paths.
Classes and Objects Encapsulation
Chapter 6 Methods: A Deeper Look
The Problem You are writing a program that accepts from the command line a number and that number tells the application how many numbers to read from standard.
Chapter 10 Datapath Subsystems.
11.8 Length of Curves Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 20 Hash Tables.
Copyright © 2011 Pearson Education, Inc
Searching for Guinea Pig B: Case Study in Online Research
Chapter 5 Algorithm Analysis.
Chapter 9 Carrano Chapter 10 Small Java
Encapsulation September 13, 2006 ComS 207: Programming I (in Java)
By Rajanikanth B OOP Concepts By Rajanikanth B
Basic OOP Concepts and Terms
The Facts to Be Explained
Alternate Proofs of Selected HO Theorems
Introduction: Some Representative Problems
Chapter 8 Inheritance Part 2.
Information Hiding and Encapsulation Section 4.2
Circuit Characterization and Performance Estimation
The Classical Model with Many Goods
The Object Paradigm Classes – Templates for creating objects
Chapter 2 Part 1 Data and Expressions.
Chapter 6 Dynamic Programming.
Encapsulation.
Chapter 2 Reference Types.
Chapter 4 Greedy Algorithms.
Copyright © 2011 Pearson Education, Inc
CSG2H3 Object Oriented Programming
Chapter 6: A First Look at classes
Presentation transcript:

Classes and Objects housefly object Insect class mosquito object The Insect class defines the fields and methods that will exist in all objects that are an instances of the Insect class. The housefly object is an instance of the Insect class. The process of creating a new object is called instantiation. mosquito object The mosquito object is an instance of the Insect class. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Why? Programming simulates real world activities (usually). The real world is populated by objects, actors who behave in certain ways. Object oriented programming is a natural way to simulate the objects and behaviors in real world activity. (but you can’t take the analogy too far) Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Also why Objects provide a way to encapsulate data and behavior into one package. That package will operate in known ways and then can become part of a larger whole. Look at the java services we have used. They are classes and objects which are “tried and true”. OOP fosters quality code and code reuse. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Object-Oriented Programming Data (Fields) Methods That Operate on the Data Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Object-Oriented Programming Object-oriented programming combines data and behavior via encapsulation. Data hiding is the ability of an object to hide data from other objects in the program. Only an object’s methods should be able to directly manipulate its data. Other objects are allowed manipulate an object’s data via the object’s methods. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Object-Oriented Programming Data (Fields) typically private to this object Methods That Operate on the Data Code Outside the Object Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Object-Oriented Programming Data Hiding In object-oriented programming, a class “knows itself”. Data is accessed only through well-defined interfaces. These interfaces are the methods. The interfaces protect the data from corruption. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Classes and Instances Many objects can be created from a class. Each object is independent of the others. String person = “Jenny”; String pet = “Fido”; String favoriteColor = “Blue”; Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.

Classes and Instances Each instance of the class String contains different data. The instances are all share the same design. Each instance has all of the attributes and methods that were defined in the String class. Classes are defined to represent a single concept or service. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved.