Lecture 12 March 16, 2000. The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Inheritance Inheritance Reserved word protected Reserved word super
Introduction to Object Oriented Programming Java.
ITEC200 – Week03 Inheritance and Class Hierarchies.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
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.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
1 Introduction to CS Agenda Syllabus Schedule Lecture: the management of complexity.
Object-oriented Programming Concepts
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
BACS 287 Basics of Object-Oriented Programming 1.
Inheritance using Java
Object-Oriented Programming Concepts
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.
Introduction to Object-oriented programming and software development Lecture 1.
BCS 2143 Introduction to Object Oriented and Software Development.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Chapter 8 More Object Concepts
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
© S Ramakrishnan, Monash University oops1.ppt 1 Object-Oriented Programming Systems SFT3021 Semester Lecturer: Sita Ramakrishnan
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
Inheritance in the Java programming language J. W. Rider.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
: Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1.
Object Oriented Programming
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
OO terminology & objectives §Encapsulation l don’t touch my private data l get/set it using my public/package methods §Inheritance l a parent provides.
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.
Session 06: C# OOP-3 Inheritance and Polymorphism. Static and dynamic type of an object. FEN AK - IT: Softwarekonstruktion.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Java Software Solutions Lewis and Loftus Chapter 8 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Inheritance -- Introduction.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Module 9. Dealing with Generalization Course: Refactoring.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
CSCE 240 – Intro to Software Engineering Lecture 3.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
Object Oriented Programming in Java Habib Rostami Lecture 2.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Object-Oriented Programming
Sections Inheritance and Abstract Classes
Object Oriented Programming
OOP: Encapsulation &Abstraction
Reuse Separate classes could be developed for all the different objects that are needed in each program. However that would be wasteful. Often many functionalities.
Inheritance ITI1121 Nour El Kadri.
Inheritance and Polymorphism
Chapter 11 Object-Oriented Design
Chapter 10 Thinking in Objects
Inherited Classes in Java
Advanced Java Programming
Final and Abstract Classes
Presentation transcript:

Lecture 12 March 16, 2000

The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same name as a class or instance variable. –(Other languages are not so restrictive.) [ Scope.java ]Scope.java

Object-Oriented Programming (OOP) Goals –Reduce development costs –Improve software reliability –Reduce maintenance costs Principles –Encapsulation –Inheritance –Polymorphism

Goals Reduce development costs –Code reuse –Find bugs sooner (easier to fix) –Enforce good programming practices Increase reliability –Find bugs automatically Reduce maintenance costs –Real-world programs last a long time

OOP Principles Encapsulation Programs = Algorithms + Data Structures –Use classes to put data and the algorithms (methods) that manipulate those data together. Example: You can use class Vector without knowing how it is implemented internally. –Public methods provide the “interface” to the class. –As long as you don’t change the signatures of the public methods, you can change the internal details all you want. Benefits: Modularity, Maintainability

Encapsulation Public Methods Private MethodsPrivate Data Class “Capsule”

Modularity Separate Compilation Parallel Development Intellectually Manageable “Chunks”

Maintainability Lifetime of a Program –Design Decide what it will do and how –Implement Write and test the code –Maintain Fix bugs and add features Academia –Professor designs. You write and test. End.

Object-Oriented Programming Inheritance A class can extend another class. –Java supports “single inheritance.” A subclass extends a superclass. Leads to a class hierarchy; a tree of classes. root Nodes:

Java Class Hierarchy The root class is java.lang.Object –All other classes are direct or indirect subclasses of class Object –You don’t have to declare that a class is a subclass if it is a direct subclass of Object: class MyClass { … } class MyClass extends Object { … } class MyClass extends java.lang.Object { … } Consider class javax.swing.JApplet

Subclasses and Superclasses A subclass inherits methods and fields from its superclass, super-superclass, etc. –A subclass object therefore is a superclass object, but with additional features. –A superclass may override some or all of its superclass’ methods. Exercise: Write a superclass and a subclass that both implement a method named identifyYourself(), but differently from each other. –Have the subclass provide an additional method, saySomethingNice(). –[ TestClasses.java ]TestClasses.java