CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) 235-5932 * Acknowledgement:

Slides:



Advertisements
Similar presentations
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Advertisements

Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Road Map Introduction to object oriented programming. Classes
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
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.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C++ fundamentals.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
OOP Languages: Java vs C++
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Introduction To System Analysis and design
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Chapter 8 More Object Concepts
CISC6795: Spring Object-Oriented Programming: Polymorphism.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
© S Ramakrishnan, Monash University oops1.ppt 1 Object-Oriented Programming Systems SFT3021 Semester Lecturer: Sita Ramakrishnan
CSCI-383 Object-Oriented Programming & Design Lecture 13.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
OOP IN PHP `Object Oriented Programming in any language is the use of objects to represent functional parts of an application and real life entities. For.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
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.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Object-Oriented Programming Chapter Chapter
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
ISBN Object-Oriented Programming Chapter Chapter
Introduction to Object-Oriented Programming Lesson 2.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Classes, Interfaces and Packages
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
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.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
ISBN Chapter 12 Support for Object-Oriented Programming.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
Object-Oriented Programming: Classes and Objects.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
OOP What is problem? Solution? OOP
Chapter 3: Using Methods, Classes, and Objects
Can perform actions and provide communication
Can perform actions and provide communication
Can perform actions and provide communication
Final and Abstract Classes
Presentation transcript:

CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement: This lecture is based on material courtesy of Monash University

2 CS451 - Lecture 2 Content Basic OOConcepts  AbstractDataTypes  Encapsulation  MessageSending Classes, Objects and State  Attributes  Instance  Class  Object creation & destruction Object Behaviour  Methods  InstanceMethods  ClassMethods  MethodOverloading Object Interfaces  Interface classes  AccessModifiers  Inheritance

3 CS451 - Lecture 2 Object-oriented programming Construction of system which is structured collections of "classes", or abstract data type implementations. These classes produce runtime instances called "objects" which communicate by sending messages to each other. Each ADT encapsulates the state and behavior of its real- world counterpart. Using Java, OO concepts will be explanined. Compare this with how structured programs are developed!

4 CS451 - Lecture 2 Object Oriented Concepts Abstract Data Type (ADT) –an abstract representation of a real-world entity Encapsulation –the combination of state and behavior into a single structure, whilst hiding the implementation Message sending –the process by which objects communicate Classes and objects –ADT implementations and their runtime equivalents

5 CS451 - Lecture 2 Abstract Data Types (ADTs) Information Hiding and ADTs ( )  An ADT is a specification of a real-world "object" with both hidden state and public behavior  Implementation (class body) hides the data representation and function realization at lower level  The name of a class names an ADT (the interface(s)), the type of data (the instances of the class), and the implementation (the hidden details)

6 CS451 - Lecture 2 Abstract Data Types (ADTs)  E.g. int:primitive Java datatype with state (i.e., the value it holds), but no internal behaviour  E.g.

7 CS451 - Lecture 2 Encapsulation: state plus behavior the combination of data and functionality into a single entity, with the implementation hidden from external entities  the other side of the ADT coin, of the separation of interface and implementation  a "black-box" approach to designing OO systems

8 CS451 - Lecture 2 Encapsulation: state plus behavior  can only be achieved by "hiding" details of a class' implementation and letting other classes communicate with it only through a well defined set of messages (message sending)

9 CS451 - Lecture 2 Message sending  Message sending is the technique objects use to communicate with each other (similar to calling a function)  Message handling: the same message can be sent to different objects, each may "respond" in a different way (polymorphism)  Methods of objects - comparable to function definitions - define the "response" of an object to a message.

10 CS451 - Lecture 2 Message Sending  For example, if a bank Customer wished to deposit some money into their Account, the Customer object would send the "deposit" message to their Account object, along with an amount to deposit

11 CS451 - Lecture 2 Classes, Objects and State A class may only exist at compile time is a template/pattern for an object "only exists once" is an implementation of an ADT is by a class declaration An Object exists at runtime only is created/instantiated from a class specification can be created many times from one class is a runtime instance of a class is returned by the new operator

12 CS451 - Lecture 2 Attributes... are used to represent state. part of the interface and accessible only through methods or hidden and represent the internal state of objects.  variables which have some connection to a class and are declared, initialized, referenced and assigned  primitive, user-defined, or a class from the JDK API

13 CS451 - Lecture 2 Attributes  Instance variables store information pertaining to one particular object's state (by far the most common of the two types of attribute)  Class variables store information pertaining to all objects of one class

14 CS451 - Lecture 2 Instance variables Visible inside class; each instance object has its own values associated to the instance variable  To access an instance variable  from within it's class, the name of the variable itself is used  from outside its class, through a valid object reference  Initialization performed when object is created

15 CS451 - Lecture 2 Class variables  Value shared by all instances of the class; sort of a "global variable" to all instances  Details  Declared with the static keyword  Initialized before main runs  Writable only for methods in class (unless public)  If public, use dotting ClassName.ClassAttribute to access from outside class;

16 CS451 - Lecture 2 Object creation and destruction Objects often require special initialization when they are first created. constructors are automatically called once a new instance object is created. finalize is required when an object is just about to be de-allocated. (Java: not allow manual memory allocation)

17 CS451 - Lecture 2 Object creation and destruction  new: allocates the object and returns a reference to the newly-instantiated object  invokes all instance variable initialization  invokes the constructor to initialize the object. finalize  not equivalent to a destructor (release all critical resources implicitly)  Called before the garbage collector frees up the object's memory

18 CS451 - Lecture 2 Object behavior (Method) defined by its methods, which have some connection to a class  associated with a signature: a unique identifying name and parameter list, and a return type  all parameters are passed by value  instance methods (invoked on an object), and class methods (invoked on the class itself, even if no objects of that type exist)

19 CS451 - Lecture 2 Instance methods methods you call on instances of a class. They make up the majority of the behavior in most classes. Encapsulation "requires" accessor and mutator methods for all instance variables accessing an instance method from outside the class is through a current object reference with the dot (.) notation

20 CS451 - Lecture 2 Class methods  Can only operate on class variables (e.g., static)  To access a class method from outside the class, you must use the name of the class with the dot (.) notation as in Class.foo  Use class method name to access from within the class

21 CS451 - Lecture 2 Method overloading Method overloading occurs whenever two or more methods have the same name, but different parameter lists in terms of number and/or type of parameters  resolved by matching number and types of parameters in method invocation against arguments in method definition  if no exact match, type coercions (type casts) are used to find the closest match

22 CS451 - Lecture 2 Object Interfaces The interface keyword directly supports the separation of interface definition (of abstract data types) from their implementation. The implements keyword indicates that a class implements one or more interfaces. A class must conform with any interface it implements. This means every method specified in the interface must be implemented.

23 CS451 - Lecture 2 Interface Classes Interface classes list only the signatures not bodies of methods. Interfaces support a kind of multiple inheritance: an interface or an implementation class can be subclass (can implement) several interfaces. No code is inherited from any of the interface class.

24 CS451 - Lecture 2 Interface Classes  The larger a class' public interface, the closer the coupling of that class to other classes  The closer a class' coupling, the more work is required by client classes when the supplier changes  to decrease coupling and increase modularity  Keep interface classes small  Use Java access modifiers wisely to maintain encapsulation and reduce coupling  Keep all state information inside the class

25 CS451 - Lecture 2 Access modifiers: private and public In implementation classes, access modifier is attached to both methods and attributes at declaration time to govern their visibility to other classes. A class' public interface is the set of methods and attributes (accessor methods) accessible from outside the class. Public/Private: Accessible from any other class - provided an object reference is available / Accessible only from within the class in which they are declared

26 CS451 - Lecture 2 Inheritance class A is the... –parent –ancestor –superclass –base class class B is the… –child –descendent –subclass –derived class

27 CS451 - Lecture 2 Inheritance A child class will inherit all non-private attributes and methods from it's parent  Subclasses are said to "specialize" superclasses' functionality and/or state  Base classes are often left unimplemented, and serve merely as a specification for a minimum subset of data and functionality in derived classes

28 CS451 - Lecture 2 Inheritance  accomplished through the use of the extends keyword  Inheritance implies an "is-a" relationship between two classes (i.e., class B "is-a" type of class A, if class B inherits from class A)  If the derived class implements additional functionality to the parent class, the relationship is between the two classes is referred to as is-a- kind-of rather than just "is-a".