Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.

Slides:



Advertisements
Similar presentations
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Advertisements

Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Classes and Objects Systems Programming.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
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.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
CSC 205 Java Programming II Defining & Implementing Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Chapter 3 (B) 3.5 – 3.7.  Variables declared in a function definition’s body are known as local variables and can be used only from the line of their.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Objects and Classes.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
Comp1004: Building Better Objects II Encapsulation and Constructors.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Classes (Part 1) Lecture 3
More Sophisticated Behavior
Examples of Classes & Objects
Object Oriented Programming using Java - Class Instance Variables
Chapter 3: Using Methods, Classes, and Objects
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
Building Java Programs
Object Based Programming
Encapsulation & Visibility Modifiers
Corresponds with Chapter 7
Classes & Objects: Examples
Encapsulation and Constructors
Introduction to Classes and Objects
Defining Classes and Methods
Object Oriented Programming in java
NAME 436.
Information Hiding and Encapsulation Section 4.2
Classes and Objects Systems Programming.
CSG2H3 Object Oriented Programming
Chapter 5 Classes.
Introduction to Classes and Objects
Presentation transcript:

Classes and Class Members Chapter 3

3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object that calls methods on another object or class. The interface details what the class does, but not how it does it.

3 Private Implementation The private implementation of a class is the detailed explanation of how the class does its work. Clients do not know these details.

3 Encapsulation A good contract promises a well- defined area of responsibility. Each class should fully encapsulate (contain) all its responsibilities. What the class does should be clear but the details of how it does it should be hidden.

3 What is data hiding? Data hiding is a term used to indicate that a class’s internal state is hidden from its clients.

3 Delegation A class should fulfill and restrict itself to one area of responsibility. Classes should delegate outside responsibilities to other classes.

3 Class Fields Class fields hold the class data. Each field has a type: Intrinsic Types The Java language defines eight intrinsic types Java Library Types User-Defined Types Classes defined by the programmer

3 Public vs. Private Fields The keywords public and private are referred to as access modifiers. Use private keyword to hide field from clients. Use public keyword to allow clients access to field.

3 Methods Methods define the behavior of the class. Methods can return a value: Return type can be an intrinsic type or an object. Use the keyword void if a value is not to be returned by the method. Methods can accept parameters: A parameter is an object you pass in to the method when you call it. Parameters follow the same naming conventions as field names.

3 Accessor and Mutator Methods Accessor methods return information Typically named to indicate that a value is being returned: getAge() getAccountBalance() Mutator methods modify the state of the object. Typically named to indicate that a value is being changed: setAge() addDeposit()

3 Why Use Accessors and Mutators? Follows the concept of data hiding Allows the class designer to change how a method is implemented without rewriting clients

3 What is a constructor? A constructor is a special method that creates an instance of your class.

3 Constructors Constructors initialize objects with valid values. Constructors have special rules: May accept parameters Never marked with a return type A default constructor: Takes no parameters Is provided by the compiler if you do not provide one

3 Static Members Static members belong to the class and are shared by all instances of the class. Declared using the static keyword Can be accessed without an instance of the class

3 Dot Operator The dot operator indicates that a method or member field (right side of dot) belongs to the object or class (left side of dot). ClassName.someStaticMemberField ObjectName.someMethod()

3 The this Keyword Is a self-reference to the current object Provided only in instance methods, not in static methods