1 Inheritance & Interface. 2 Why Inheritance? Common properties? Methods to send congratulations to Employees and Customers Public Sub SendCongratulationsE(ByVal.

Slides:



Advertisements
Similar presentations
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Advertisements

Advanced Object Oriented Concepts Tonga Institute of Higher Education.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Chapter 11: Implementing Inheritance and Association Visual Basic.NET Programming: From Problem Analysis to Program Design.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ITEC200 – Week03 Inheritance and Class Hierarchies.
More about classes and objects Classes in Visual Basic.NET.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Compunet Corporation1 Programming with Visual Basic.NET Inheritance Lecture # 10 Tariq Ibn Aziz.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Object-Oriented Programming in Visual Basic.NET. Overview Defining Classes Creating and Destroying Objects Inheritance Interfaces Working with Classes.
Object-Oriented Programming: Inheritance
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
Inheritance Chapter 14. What is inheritance?  The ability to create a class from another class, the “parent” class, extending the functionality and state.
Inheritance using Java
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Module 7: Object-Oriented Programming in Visual Basic .NET
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Programming Pillars Introduction to Object- Oriented Programming.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Inheritance Extending Class Functionality. Polymorphism Review Earlier in the course, we examined the topic of polymorphism. Many times in coding, we.
Inheritance Building one object from another. Background Object-oriented programming is normally described has offering three capabilities Encapsulation:
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would.
Session 04 Module 8: Abstract classes and Interface Module 9: Properties and Indexers.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Introduction to Object-Oriented Programming Lesson 2.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Object-Oriented Programming: Inheritance and Polymorphism.
Chapter 2 11/18/2015 © by Pearson Education, Inc. All Rights Reserved. Lect9 GC 2011.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Interfaces Are used to model weak inheritance relationships Object-inheritance.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Section 3: Component/Object Oriented Programming, Events, and Delegates in.NET Jim Fiddelke, Greenbrier & Russel.
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 New class derived from existing class Software engineering technique Software reuse : faster, easier, cheaper Parent class (supper class):
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
These materials where developed by Martin Schray
Advanced Programming in Java
Advanced Programming in Java
Inheritance and Polymorphism
Inheritance AKEEL AHMED.
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Inheritance
IS437: Fall 2004 Instructor: Dr. Boris Jukic
Interfaces.
Object-Oriented Programming: Inheritance
Advanced Programming in Java
Object-Oriented Programming: Inheritance
Chapter 14 Abstract Classes and Interfaces
CIS 199 Final Review.
Assessment – Java Basics: Part 2
Inheritance Lakshmish Ramaswamy.
Object-Oriented Programming: Inheritance
Presentation transcript:

1 Inheritance & Interface

2 Why Inheritance? Common properties? Methods to send congratulations to Employees and Customers Public Sub SendCongratulationsE(ByVal employees() As Employee … End Sub Public Sub SendCongratulationsC(ByVal customers() As Customer … End Sub Example InheritanceExample1 Cannot reuse the same procedure Inheritance: –Sharing common code and properties –The process of extending the functionality of a class by adding new properties and methods and creating in this way a new class (the Derived class) EmployeeCustomer

3 Simple Inheritance EmployeeCustomer Person Public Class Person... End Class Public Class Customer Inherits Person... End Class Public Class Employee Inherits Person... End Class ‘ To send congratulations Public Sub SendCongratulation(ByVal persons() As Person)... End Sub

4 Inheritance Issues Visibility –Public, Protected Keyword MyBase –i.e. super in Java –MyBase.New() Multi-level Inheritance

5 Overriding (Polymorphism) (1) Derived classes may have different behavior with their base classes for the same method Public Class Employee Inherits Person... Public Overridable Function GetMontlyPay() As Decimal Return m_salary / 12 End Function End Class Public Class Manager Inherits Employee... Public Overrides Function GetMontlyPay() As Decimal Return MyBase.GetMontlyPay() + m_bonus End Function End Class

6 Overriding (Polymorphism) (2) ‘ Calling methods, depends on the Type of the object Dim e As Employee, m As Manager … e = m d = m.GetMontlyPay()‘ call Manager’s d = e.GetMontlyPay()‘ call Manager’s too! Dim e2 As Employee … d = e.GetMontlyPay()‘ call Employee’s Stepping through InheritanceExample2

7 Abstract Classes Abstract classes are classes with Abstract methods (with definition but no implementation) Abstract classes cannot be instantiated Public MustInherit Class Account‘ abstract class Protected m_balance As Decimal... Public MustOverride Sub CloseMonth()‘ abstract method End Class Public Class SavingsAccount Inherits Account... Public Overrides Sub CloseMonth()‘ provide actual implementation If m_balance < 0 Then ' If the balance is negative, apply a charge of 25 dollars m_balance -= 25 Else ' apply an interest of whatever the interest ' stored in the s_interest value m_balance *= 1 + s_interest End If End Sub End Class

8 Interface (1) A definition for certain behavior. This behavior is implemented by any class that implements the interface. Act as a Contract, the class implementing the interfaces “promises” to provide the implements Similar to classes, can have members properties and methods, but NOT fields All properties and methods must be abstract No modifiers for the properties and methods are allowed A class can implement multiple interfaces Public Interface IComparable Function CompareTo(Byval o as Object) As Integer End Interface

9 Interface (2) Public Class Test Implements IComparable … Function CompareTo(ByVal o As Object) As Integer _ Implements IComparable.CompareTo Dim t As Test = CType(o, Test) If m_testNo = t.m_testNo Then Return 0 If m_testNo < t.m_testNo Then Return -1 Return 1 End Function End Class

10 Interfaces Vs Inheritance A class can inherit from one class only (single inheritance), but it can implement any number of interfaces An interface is different from a base class: An interface defines behavior only, whereas a base class can hold state (have fields), define, and implement behavior A base class defines what a derived class is; whereas an implemented interface defines how the object behaves in certain circumstances An object is not said to be an IComparable, but it is said to be comparable, it can behave as described by the interface, but is an instance of the base class

11 Interface Inheritance Interface can inherit from other interfaces Public Interface ITest Inherits IComparable, ICloneable ReadOnly Property textValue() As String End Interface Example InterfaceExample1