Introduction to Classes, Objects, Methods and Attributes Lecture # 5.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Chapter 6: A First Look at classes. Object-Oriented Programming  Object-oriented programming is centered on creating objects rather than procedures.
Chapter 1 Object-Oriented System Development
Introduction To System Analysis and Design
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Object Oriented System Development with VB .NET
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java: Early Objects Third Edition by Tony Gaddis Chapter.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
ASP.NET Programming with C# and SQL Server First Edition
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Object Oriented Programming
Introduction to Classes, Objects, Methods and Attributes Lecture # 2.
Introduction to Object-oriented programming and software development Lecture 1.
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.
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.
Introduction To System Analysis and Design
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
JavaScript, Fourth Edition
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 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.
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.
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
© 2004 Pearson Addison-Wesley. All rights reserved September 12, 2007 Encapsulation ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
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.
Source Mastering UML with Rational Rose 2002 Information System Engineering Introduction to UML.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
© 2010 Pearson Addison-Wesley. All rights reserved. 6-1 Chapter Topics Chapter 6 discusses the following main topics: –Classes and Objects –Instance Fields.
Lecture 19: Introduction to Classes Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 3 A First Look at Classes and Objects.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, 2005 Pearson Addison-Wesley. All rights reserved. Chapter 6 Slide.
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.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
1 Design Object Oriented Solutions Object Oriented Analysis & Design Lecturer: Mr. Mohammed Elhajj
CS16: UML’s Unified Modeling Language. UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has.
CSIS 123A Lecture 1 Intro To Classes Glenn Stevenson CSIS 113A MSJC.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Copyright © 2011 Pearson Education, Inc. Starting Out with Java: Early Objects Fourth Edition by Tony Gaddis Chapter 3: A First Look at Classes and Objects.
Object Oriented Programming
Chapter 3 Classes & Objects
A first Look at Classes.
Introduction to Classes
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Introduction to Classes
Classes and Objects housefly object Insect class mosquito object
Encapsulation September 13, 2006 ComS 207: Programming I (in Java)
Basic OOP Concepts and Terms
2.1 Introduction to Object-Oriented Programming
Lecture 8 Object Oriented Programming (OOP)
Chapter 6: A First Look at classes
Presentation transcript:

Introduction to Classes, Objects, Methods and Attributes Lecture # 5

1-2 Object-Oriented Programming Object-oriented programming is centered on creating objects rather than procedures. Objects are a melding of data and procedures that manipulate that data. Data in an object are known as attributes. Procedures in an object are known as methods.

1-3 Object-Oriented Programming Data Hiding Data hiding is important for several reasons. – It protects attributes from accidental corruption by outside objects. – It hides the details of how an object works, so the programmer can concentrate on using it. – It allows the maintainer of the object to have the ability to modify the internal functioning of the object without “breaking” someone else’s code.

1-4 Object-Oriented Programming Code Reusability Object-Oriented Programming (OOP) has encouraged component reusability. A component is a software object contains data and methods that represents a specific concept or service. Components typically are not stand-alone programs. Components can be used by programs that need the component’s service. Reuse of code promotes the rapid development of larger software projects.

3-5 Encapsulation Classes should be as limited in scope as needed to accomplish the goal. Each class should contain all that is needed for it to operate. Enclosing the proper attributes and methods inside a single class is called encapsulation. Encapsulation ensures that the class is self- contained.

1-6 Classes and Objects Components are objects. The programmer determines the attributes and methods needed, and then creates a class. A class is a collection of programming statements that define the required object A class as a “blueprint” that objects may be created from. An object is the realization (instantiation) of a class in memory.

1-7 Object-Oriented Programming Object Attributes (data) Methods (behaviors / procedures)

1-8 Classes and Objects Classes can be used to instantiate as many objects as are needed. Each object that is created from a class is called an instance of the class. A program is simply a collection of objects that interact with each other to accomplish a goal.

1-9 Classes and Objects Insect class The Insect class defines the attributes and methods that will exist in all objects that are an instances of the Insect class. housefly object The housefly object is an instance of the Insect class. mosquito object The mosquito object is an instance of the Insect class.

3-10 Designing a Class When designing a class, decisions about the following must be made. – what data must be accounted for, – what actions need to be performed, – what data can be modified, – what data needs to be accessible, and – any rules as to how data should be modified. Class design typically is done with the aid of a Unified Modeling Language (UML) diagram.

3-11 UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has three main sections. Class Name Attributes Methods UML diagrams are easily converted to Java class files. There will be more about UML diagrams a little later. The class name should concisely reflect what the class represents.

3-12 Attributes The data elements of a class define the object to be instantiated from the class. The attributes must be specific to the class and define it completely. Example: A rectangle is defined by – length – width. The attributes are then accessed by methods within the class.

3-13 Methods The class’ methods define the actions that an instance of the class can perform Methods headers have a format: AccessModifier ReturnType MethodName(Parameters) { //Method body. } Methods that need to be used by other classes should be made public.

3-14 Methods The attributes of a class might need to be: – changed, – accessed, and – calculated. The methods that change and access attributes are called accessors and mutators.