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.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Abteilung für Telekooperation Softwareentwicklung 2 UE SE2UE_ Vererbung (Inheritance)
Chapter 1 Inheritance University Of Ha’il.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Comp 249 Programming Methodology Chapter 7 - Inheritance – Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
Chapter 10: Introduction to Inheritance
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
 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.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
Slides prepared by Rose Williams, Binghamton University Chapter 7 Inheritance.
Class Structures and Methods B.Sc. Multimedia ComputingMultimedia Authoring.
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Inheritance using Java
Introduction to Object-oriented programming and software development Lecture 1.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
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.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Encapsulation, Inheritance & Polymorphism. OOP Properties Encapsulation ­The process of creating programs so that information within a class is not accessible.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Lecture 12 March 16, 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.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Inheritance Inheritance allows a programmer to derive a new class from an existing one The existing class is called the super class, or parent class,
1. 2  Classes are not just containers for methods ◦ Virtually all are classes ◦ Blueprint/Cookie Cutter/Recipe ◦ Objects – instance of the class (new)
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Topics Inheritance introduction
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
CET203 SOFTWARE DEVELOPMENT Session 2A Inheritance (programming in C#)
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CompSci Reading from Files  import java.io.File;  Declare a file File fileOfCats = new File(”cats.txt”);  Use file – pass it as an argument to.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
BY:- TOPS Technologies
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Sections Inheritance and Abstract Classes
OOP: Encapsulation &Abstraction
Inheritance ITI1121 Nour El Kadri.
University of Central Florida COP 3330 Object Oriented Programming
Objects as a programming concept
Chapter 11 Object-Oriented Design
Inheritance Inheritance allows a programmer to derive a new class from an existing one The existing class is called the super class, or parent class,
University of Central Florida COP 3330 Object Oriented Programming
An Introduction to Inheritance
Object Oriented Analysis and Design
Interface.
Fundaments of Game Design
Review of Previous Lesson
Object-Oriented PHP (1)
Classes in Java Specifics for Java Copyright Curt Hill.
Chapter 7 Inheritance.
Presentation transcript:

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 are shared between objects, and it makes sense to write these so that the developer only writes them once. Less to write, more time to have fun. Easier to maintain code. If there is a bug you only need to solve it once.

Reuse Example from the real world: A TV manufacturer has created software for a TV that can view TV, change channels, view TV listings. All the normal TV features. They need to create a version with recording facilities. It would be much more sensible to use the same code for the normal features and extend the functionality to record TV as well.

Inheritance In OOP this is commonly achieved using inheritance. A new class can be made that extends another class. The new class is known as a child class/subclass of the parent class/superclass (the already existing class). The child class inherits all of the data and methods of the parent class. can declare new attributes and methods. can, if necessary, override methods to change the behaviour of the methods inherited from the parent. A child object can be assigned to a parent variable.

Libraries and API An OOP program usually consists of many classes where a lot of them are inherited from a parent class to provide the functionalities that are needed. Often the development consists of creating a library of classes. These can be shared and reused in extensions of the application or even shared as completely new programs . These are often called Application Programming Interfaces (API).

Organizing inheritance Class A Class B Class C Class D Class E

Organizing inheritance - modifiers When declaring attributes and methods the developer can control which other objects are able to access the attributes and call the methods. These are called modifiers, and there are different levels of access: Private level: Only the object can access. Protected level: Only the object or objects of subclasses can access. Package level: Only objects organised in the same package can access. Public level: Any object can access.

Controlling access Modifier Class Classes inside package Subclasses outside package World public Y protected N No modifier (package) private

Organizing inheritance - modifiers Class A Access: Public Protected Class B Class C Class D Class E

Organizing inheritance - modifiers Class A Class B Class C Access: Public Class D Class E

Organizing inheritance - overriding Class A protected int count Class B Class C Access: this super Class D Class E protected int count

Organizing inheritance - overriding Class A protected int doSomething() Class B Class C Access: super Class D Class E protected int doSomething() Change behaviour in subclass. Can still call superclass’ method to Provide original behaviour.