Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
Chapter 10: Introduction to Inheritance
ITEC200 – Week03 Inheritance and Class Hierarchies.
Road Map Introduction to object oriented programming. Classes
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Terms and Rules Professor Evan Korth New York University (All rights reserved)
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Chapter 13: Object-Oriented Programming
Chapter 10 Classes Continued
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
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.
Programming in Java CSCI-2220 Object Oriented Programming.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
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.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 5 Introduction to Defining Classes
© 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.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
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.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Object-Oriented Design
OOP: Encapsulation &Abstraction
Classes (Part 1) Lecture 3
Inheritance-Basics.
Inheritance and Polymorphism
Object Based Programming
Lecture 22 Inheritance Richard Gesick.
Packages and Interfaces
CIS 199 Final Review.
Final and Abstract Classes
Lecture 10 Concepts of Programming Languages
Chapter 11 Inheritance and Encapsulation and Polymorphism
Presentation transcript:

Summing Up Object Oriented Design

Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering data and methods with safe and reliable boundaries. Inheritance extending abstractions to include more detailed knowledge Polymorphism allowing flexibility in naming entities & expressing abstractions

1. Traditionally encapsulation and abstraction have been implemented by the concept of abstract data type: a representation of an entity that includes the information about it and operations that can be performed on it. In Java this is a class. 2. Encapsulating data and methods maintains the integrity of the data: ensures it is not changed unintentionally or in any other way than intended. (This is very important in large programs worked on by many programmers.) Encapsulation provides information hiding: details of methods are not visible by a client.

3. Packages provide a high degree on encapsulation but provide a means for classes to access data fields defined in other classes in the package. The package to which a class belongs is declared at the top of the file and all classes in the package should be stored in the same directory and that should have the same name as the package. ( see p.398) Data fields with default visibility (not declared private, protected or public) are accessible by any class in the same package.

Remember: declaring data fields public allows any class to access them. Dangerous! Avoid! The import statement allows class members (data fields and methods) to be referred to by their class names without the package name. (compare bottom p.399 with bottom p.400) Files that do not declare themselves part of a specific package are considered part of the default package. What is the problem with this? Data fields without scope modifiers are accessible to any class also in the default class - encapsulation is lost.

A library is a collection of classes organized into a package. Can you name some we have used? simpleIO, java.awt, java.applet, and java.lang (automated loaded - no import needed.) What does * mean? everything for example: Import java.awt.* means everything in the awt package.

Sometimes access is needed to data fields from a class outside the package that extends a class inside the package. How can this be accomplished without declaring the data field public? protected. (see p & table p.404) If you do want a class member to be public, what must the class itself be declared? public

4. The public members of a class constitute the rules the programmer has made for accessing the class. This is called Application Programmers Interface

5. Do Objects Communicate? Yes. Client classes send messages to support classes. Support classes are the recipients and respond to the messages. Message passing and maintaining the right level of abstraction is controlled by defining methods that are constructors, accessors, and modifiers.

Other types of methods are operators and destructors. Destructors are methods which delete instances of a class (objects) but Java provides a garbage collector that searches for objects no longer used and returns that memory space as available for other use. ( The programmer does not have to do it.)

6. The use of classes results in modular programming which enables a problem to be divided into smaller units which can be reused. Programmers can adapt existing solutions to be reused in new problems. This is implemented by the inheritance between a superclass and subclass. A subclass can invoke the constructor of its superclass by placing the instruction super(argument list); as the first line in its own constructor. (see p.392 &387)

7. Polymorphism dictionary meaning: many shaped. In Java - methods may take a variety of forms. ( Think about the getInt() method in the SimpleGUI class. Some students used only 1 argument, a string, and others used 3 arguments: a string and 2 integers. Did the method work if only the string and 1 integer was used?

Three types of polymorphism: 1. Across classes: methods that have the same name but carry out the task by a different procedure in each class. ( see p.409 computeArea() ) 2. Method overloading: methods within one class that have the same name but different procedures. Requirement: different argument lists. (The compiler identifies which of the methods with the same name is being referenced by the method signature : its name, return type, and argument list.) 3. Method overriding: a method exists in a subclass that has the same name as a method in the superclass. (The subclass version is used.)

8. Class members and instance members: static and final Each time we create an instance of a class, that object has its own data fields which usually contain values that are different from the values in the data fields of other instances of the class. These data fields are called instance data fields or instance members. Java provides a means for data fields which will always contain the same value, when used in any situation. These are called class data fields or class members. These are shared by all instances of the class, thereby saving memory.

Class data fields or methods are created by the keyword: static. Can you think of an examples? Math.PI, Color.black, ioSample.getInt() When the keyword final is also used, the data field becomes constant (the value in the data field may not be modified. Remember: static (class) methods can manipulate only class data fields - not instance data fields. (see p. 419)

Notes: A class that is final cannot be extended. A method that is final cannot be overridden. A method that is static may be accessed either through its class name, or through a class instance. (see chart p.424)

9. static void main() ensures that there is only one occurrence of this method and it resides in the class (not in an instance). Therefore there is always only one entry point into your program.

10. An abstract class is an outline of a class. It contains method names without bodies. All classes that extend an abstract class must define each method. Can you create an instance of an abstract class? No. The concept of abstract class supports good organization of classes. An abstract class would be at the highest level in the hierarchy because it contains all the data fields and methods common to all subclasses in the hierarchy. See p. 425 & p.428.

11. Does Java support multiple inheritance? No. (a class can extend only one superclass.) However, Java provides a mechanism called an interface. The only members of an interface are abstract methods and final class data fields. A class implements an interface (not extend it). The advantage is that classes have the benefits of a hierarchical structure without being tied to a superclass. Often used in GUI and graphic programs. See p. 573 & 576.