SlideShare una empresa de Scribd logo
1 de 21
+
Object Inheritance
Systems Analysis and Design
Michael Heron
+
Introduction
 Last week we talked about how we use natural language
analysis to end up with the bare bones of a potential class
diagram.
 We missed out some parts of it because we haven’t yet covered the
fundamentals.
 In this lecture we’re going to look at the relationship between
specific classes.
 Inheritance
 Composition
 Aggregation
 These allow us to arrange classes in terms of how they
interact.
+
Has-A and Is-A
 In our natural language analysis, the key phrases we look for
are variations of ‘has a’ and ‘is a’
 Has a represents a composition or aggregation
 Is a represents an inherited relationship.
 A car is a vehicle.
 A case has an engine.
 We do this as one of our later passes over the document.
 That way we can ignore relationships to classes that have already
been discarded.
+
Inheritance
 One of the primary ways in which object orientation permits
effective structuring of code is through inheritance.
 Different languages permit different kinds of inheritance.
 Java and the .NET languages offer single inheritance.
 Each class can inherit from only one parent.
 C++ offers multiple inheritance.
 Classes can inherit from more than one parent.
 Multiple inheritance is more powerful.
 But also very difficult to do right.
 Single inheritance is more limited.
 But design patterns (more on that later) let us deal with those
limitations.
+
Inheritance
 The concept of inheritance is borrowed from the natural world.
 You get traits from your parents and you pass them on to your
offspring.
 In OO programming, ‘traits’ are behaviours and attributes.
 In most OO languages any class can be the parent of any other
object.
 The child class gains all of the methods and attributes of the parent.
 This can be modified, more on that in a later lecture.
 Through this basic mechanism, code can be made available
through an OO program.
+
Inheritance in the Natural World
+
Inheritance
 Inheritance is a powerful concept for several reasons.
 Ensures consistency of code across multiple different objects.
 Allows for code to be collated in one location with the concomitant
impact on maintainability.
 Changes in the code rattle through all objects making use of it.
 Supports for code re-use.
 Theoretically…
 Difficult to get around the ‘Not Invented Here’ syndrome.
 It is part of the static design of a system.
 It’s decided at design time how the different parts of the system can
interrelate.
 This can’t be changed at runtime, but design patterns permit us to work
around that.
+
Inheritance
 In most OO languages the most general case of a code system
belongs at the highest place it is shared in the inheritance
hierarchy.
 You will have seen this in player and npc and living from the
tutorial exercise.
 It is successively specialised into new and more precise
implementations.
 Children specialise their parents
 Parents generalise their children.
 Functionality and attributes belong to the most general class in
which they are cohesive.
+
Inheritance
 In .NET, the concept is simple.
 You create an inheritance relationship by having one class extend
another.
 The process of inheriting from a class is often called extension as a
result.
 The newly extended class gains all of the attributes and
methods of the parent.
 It can be used, wholesale, in place of the parent if needed.
 We can also add and specialise attributes and behaviours.
 This is the important feature of inheritance.
+
Inheritance in VB .NET
Class BankAccount
private balance as Integer
property Balance() as Integer
Get
return balance
End Get
Set (ByValue Value as Integer)
balance = Value
End Set
End Property
public Function doubleBalance()
balance = balance * 2;
end Function
End Class
+
Inheritance in Java
Class ExtendedBankAccount
inherits BankAccount
private overdraft as Integer
Function adjustBalance (byVal val as Integer) as Boolean
if Me.Balance – val < 0 – overdraft then
return false
end if
Me.Balance = (getBalance() - val);
return true;
End Function
End Class
+
Constructors And Inheritance
 When a specialized class is instantiated, it calls the
constructor on the specialized class.
 The constructor is a special method that handles the initial setup of
an object.
 If it doesn’t find a valid one it will error, even if one exists in the
parent.
 Constructors can propagate invocations up the object hierarchy
through the use of the MyBase keyword.
 MyBase always refers to the parent object in VB .NET.
 Easy to do, because each child has only one parent.
 In a constructor, must always be the first method call.
 Everywhere else, it can be anywhere.
+
Constructors
 In VB .NET, a constructor is indicated by a subroutine called
New:
Public sub New()
Me.Balance = 100
End Sub
Public sub New (ByVal value as initialBalance)
Me.Balance = initialBalance
End Sub
 We can overload these methods too.
 And all methods in Visual Basic .NET.
+
Multiple Inheritance
 The biggest distinction between C++ and .NET inheritance
models is that C++ permits multiple inheritance.
 Java, VB .NET and C# do not provide this.
 It must be used extremely carefully.
 If you are unsure what you are doing, it is tremendously easy to
make a huge mess of a program.
 It is in fact something best avoided.
 Usually.
 It’s not something you usually need.
 There are usually better and less fragile ways of accomplishing a
goal.
+
Multiple Inheritance
 What are the problems with multiple inheritance?
 Hugely increased program complexity
 Problems with ambiguous function calls.
 The Diamond Problem
 Hardly ever really needed.
 For simple applications, single inheritance suffices.
 For more complicated situations, design patterns exist to
resolve all the requirements.
 Some languages permit multiple inheritance but resolve some
of the technical issues.
 These have relatively limited traction in the real world.
+
Specialisation and Extension
 Inheritance by itself is not useful.
 It gives us a version of what we already have.
 It becomes useful because we then have three options with the
things we get from a parent class.
 We keep them as they are.
 We specialise them to change them slightly.
 We add to what we already have.
 In this way we can ensure that our new classes are
substantively different from the old classes.
 And thus are a worthwhile addition to our system.
+
Specialisation
 Specialisation means taking a behaviour and altering it.
 We can override it completely
 We can have it do something extra before passing it back to the
method in the parent.
 Whenever we provide a method with the same name in a child
class, it is called overriding.
 In VB .NET we must indicate our intention to override.
 Other languages don’t require that.
 When a method is overridden, the most specialised version of
the method gets called when we invoke it.
+
Specialisation
 Having overriden a method, we decide what happens next.
 We either ignore the code that we inherited.
 Or we pass the invocation ‘back up the chain’
 Each overridden method is responsible for deciding what is to
be done in that regard.
 In Visual Basic .NET, we can refer to methods in a parent class
through the MyBase keyword.
 We saw that in relation to constructors a little earlier.
 More on this later.
 For now, it’s okay for our class diagrams to know this can be done.
+
Extension
 With extension, we add to the attributes and behaviours we got
from the parent.
 We add new attributes
 We add new methods
 These let us give a wider range of functionality that we
otherwise would have.
 And let us branch out what our classes are for.
 This works just the same way as we saw in the VB code
example.
 We just stick the new methods and attributes in there.
+
Inheritance
 In our class tutorial, we had a Living class which was the parent
of NPC and Player.
 Both received the base functionality for representing an object which
is considered to be ‘living’ in the game.
 However, both had unique elements to go with them.
 Likely many of the methods that we inherited would end up
being overridden.
 We’ll talk about that in the tutorial.
 The inheritance allows us to share code rather than re-
implement it.
 This in turn reduces our future maintenance burden.
+
Conclusion
 Inheritance is a powerful tool in object orientation.
 One of the Great Trilogy of tools.
 Encapsulation
 Inheritance
 Polymorphism.
 VB .NET permits single inheritance only.
 This will limit us, but only until we learn how to work around it.
 Inheritance is only the start of the process.
 It must then be followed through with specialisation and
extension.

Más contenido relacionado

La actualidad más candente

Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesHitesh-Java
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMoutaz Haddara
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphismkiran Patel
 
Model-driven architecture (MDA)
Model-driven architecture (MDA) Model-driven architecture (MDA)
Model-driven architecture (MDA) Alia Hamwi
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml dataaspnet123
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion PrincipleShahriar Hyder
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanagerArati Gadgil
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVAAnkita Totala
 
Asp.net and .Net Framework ppt presentation
Asp.net and .Net Framework ppt presentationAsp.net and .Net Framework ppt presentation
Asp.net and .Net Framework ppt presentationabhishek singh
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingRAJU MAKWANA
 

La actualidad más candente (20)

Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slidesSpring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
 
Java Beans
Java BeansJava Beans
Java Beans
 
Oops in vb
Oops in vbOops in vb
Oops in vb
 
Model-driven architecture (MDA)
Model-driven architecture (MDA) Model-driven architecture (MDA)
Model-driven architecture (MDA)
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml data
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
Asp.net and .Net Framework ppt presentation
Asp.net and .Net Framework ppt presentationAsp.net and .Net Framework ppt presentation
Asp.net and .Net Framework ppt presentation
 
JavaFX Overview
JavaFX OverviewJavaFX Overview
JavaFX Overview
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 

Destacado

Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interactionMichael Heron
 
CPP18 - String Parsing
CPP18 - String ParsingCPP18 - String Parsing
CPP18 - String ParsingMichael Heron
 
Web Services: Encapsulation, Reusability, and Simplicity
Web Services: Encapsulation, Reusability, and SimplicityWeb Services: Encapsulation, Reusability, and Simplicity
Web Services: Encapsulation, Reusability, and Simplicityhannonhill
 
2CPP01 - Intro to Module
2CPP01 - Intro to Module2CPP01 - Intro to Module
2CPP01 - Intro to ModuleMichael Heron
 
2CPP07 - Inheritance
2CPP07 - Inheritance2CPP07 - Inheritance
2CPP07 - InheritanceMichael Heron
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator OverloadingMichael Heron
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility SupportMichael Heron
 
2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented ProgramMichael Heron
 
2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation FundamentalsMichael Heron
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method OverloadingMichael Heron
 
2CPP10 - Polymorphism
2CPP10 - Polymorphism2CPP10 - Polymorphism
2CPP10 - PolymorphismMichael Heron
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and AutershipMichael Heron
 

Destacado (20)

ofdm
ofdmofdm
ofdm
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interaction
 
CPP18 - String Parsing
CPP18 - String ParsingCPP18 - String Parsing
CPP18 - String Parsing
 
Web Services: Encapsulation, Reusability, and Simplicity
Web Services: Encapsulation, Reusability, and SimplicityWeb Services: Encapsulation, Reusability, and Simplicity
Web Services: Encapsulation, Reusability, and Simplicity
 
2CPP01 - Intro to Module
2CPP01 - Intro to Module2CPP01 - Intro to Module
2CPP01 - Intro to Module
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
2CPP07 - Inheritance
2CPP07 - Inheritance2CPP07 - Inheritance
2CPP07 - Inheritance
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator Overloading
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
 
2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program2CPP05 - Modelling an Object Oriented Program
2CPP05 - Modelling an Object Oriented Program
 
2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
CPP15 - Inheritance
CPP15 - InheritanceCPP15 - Inheritance
CPP15 - Inheritance
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 
2CPP10 - Polymorphism
2CPP10 - Polymorphism2CPP10 - Polymorphism
2CPP10 - Polymorphism
 
CPP17 - File IO
CPP17 - File IOCPP17 - File IO
CPP17 - File IO
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
Chapter1 Introduction to OOP (Java)
Chapter1 Introduction to OOP (Java)Chapter1 Introduction to OOP (Java)
Chapter1 Introduction to OOP (Java)
 

Similar a SAD04 - Inheritance

Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with javaAAKANKSHA JAIN
 
SAD02 - Object Orientation
SAD02 - Object OrientationSAD02 - Object Orientation
SAD02 - Object OrientationMichael Heron
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS ConceptRicha Gupta
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - EncapsulationMichael Heron
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docxFredWauyo
 
Inheritance and Substitution
Inheritance and SubstitutionInheritance and Substitution
Inheritance and Substitutionadil raja
 
oopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfoopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfJP Chicano
 
Object And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) LanguagesObject And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) LanguagesJessica Deakin
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxnaeemcse
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ FundamentalsSubhasis Nayak
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your CodeRookieOne
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++KAUSHAL KUMAR JHA
 

Similar a SAD04 - Inheritance (20)

Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with java
 
SAD02 - Object Orientation
SAD02 - Object OrientationSAD02 - Object Orientation
SAD02 - Object Orientation
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - Encapsulation
 
Java OOPs Concepts.docx
Java OOPs Concepts.docxJava OOPs Concepts.docx
Java OOPs Concepts.docx
 
Inheritance and Substitution
Inheritance and SubstitutionInheritance and Substitution
Inheritance and Substitution
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
oopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfoopsinvb-191021101327.pdf
oopsinvb-191021101327.pdf
 
Object And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) LanguagesObject And Oriented Programing ( Oop ) Languages
Object And Oriented Programing ( Oop ) Languages
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptx
 
C#
C#C#
C#
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Evolve Your Code
Evolve Your CodeEvolve Your Code
Evolve Your Code
 
Research paper
Research paperResearch paper
Research paper
 
Oop
OopOop
Oop
 
Viva file
Viva fileViva file
Viva file
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
 
C# interview
C# interviewC# interview
C# interview
 

Más de Michael Heron

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMichael Heron
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconductMichael Heron
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkMichael Heron
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityMichael Heron
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - TexturesMichael Heron
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)Michael Heron
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)Michael Heron
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationMichael Heron
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsMichael Heron
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsMichael Heron
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationMichael Heron
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - AbstractionMichael Heron
 
2CPP12 - Method Overriding
2CPP12 - Method Overriding2CPP12 - Method Overriding
2CPP12 - Method OverridingMichael Heron
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - EncapsulationMichael Heron
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and OverridingMichael Heron
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and PointersMichael Heron
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 

Más de Michael Heron (18)

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game Accessibility
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and Radiosity
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - Textures
 
GRPHICS06 - Shading
GRPHICS06 - ShadingGRPHICS06 - Shading
GRPHICS06 - Shading
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical Representation
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D Graphics
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D Graphics
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art Appreciation
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
 
2CPP12 - Method Overriding
2CPP12 - Method Overriding2CPP12 - Method Overriding
2CPP12 - Method Overriding
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - Encapsulation
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 

Último

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Último (20)

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

SAD04 - Inheritance

  • 1. + Object Inheritance Systems Analysis and Design Michael Heron
  • 2. + Introduction  Last week we talked about how we use natural language analysis to end up with the bare bones of a potential class diagram.  We missed out some parts of it because we haven’t yet covered the fundamentals.  In this lecture we’re going to look at the relationship between specific classes.  Inheritance  Composition  Aggregation  These allow us to arrange classes in terms of how they interact.
  • 3. + Has-A and Is-A  In our natural language analysis, the key phrases we look for are variations of ‘has a’ and ‘is a’  Has a represents a composition or aggregation  Is a represents an inherited relationship.  A car is a vehicle.  A case has an engine.  We do this as one of our later passes over the document.  That way we can ignore relationships to classes that have already been discarded.
  • 4. + Inheritance  One of the primary ways in which object orientation permits effective structuring of code is through inheritance.  Different languages permit different kinds of inheritance.  Java and the .NET languages offer single inheritance.  Each class can inherit from only one parent.  C++ offers multiple inheritance.  Classes can inherit from more than one parent.  Multiple inheritance is more powerful.  But also very difficult to do right.  Single inheritance is more limited.  But design patterns (more on that later) let us deal with those limitations.
  • 5. + Inheritance  The concept of inheritance is borrowed from the natural world.  You get traits from your parents and you pass them on to your offspring.  In OO programming, ‘traits’ are behaviours and attributes.  In most OO languages any class can be the parent of any other object.  The child class gains all of the methods and attributes of the parent.  This can be modified, more on that in a later lecture.  Through this basic mechanism, code can be made available through an OO program.
  • 6. + Inheritance in the Natural World
  • 7. + Inheritance  Inheritance is a powerful concept for several reasons.  Ensures consistency of code across multiple different objects.  Allows for code to be collated in one location with the concomitant impact on maintainability.  Changes in the code rattle through all objects making use of it.  Supports for code re-use.  Theoretically…  Difficult to get around the ‘Not Invented Here’ syndrome.  It is part of the static design of a system.  It’s decided at design time how the different parts of the system can interrelate.  This can’t be changed at runtime, but design patterns permit us to work around that.
  • 8. + Inheritance  In most OO languages the most general case of a code system belongs at the highest place it is shared in the inheritance hierarchy.  You will have seen this in player and npc and living from the tutorial exercise.  It is successively specialised into new and more precise implementations.  Children specialise their parents  Parents generalise their children.  Functionality and attributes belong to the most general class in which they are cohesive.
  • 9. + Inheritance  In .NET, the concept is simple.  You create an inheritance relationship by having one class extend another.  The process of inheriting from a class is often called extension as a result.  The newly extended class gains all of the attributes and methods of the parent.  It can be used, wholesale, in place of the parent if needed.  We can also add and specialise attributes and behaviours.  This is the important feature of inheritance.
  • 10. + Inheritance in VB .NET Class BankAccount private balance as Integer property Balance() as Integer Get return balance End Get Set (ByValue Value as Integer) balance = Value End Set End Property public Function doubleBalance() balance = balance * 2; end Function End Class
  • 11. + Inheritance in Java Class ExtendedBankAccount inherits BankAccount private overdraft as Integer Function adjustBalance (byVal val as Integer) as Boolean if Me.Balance – val < 0 – overdraft then return false end if Me.Balance = (getBalance() - val); return true; End Function End Class
  • 12. + Constructors And Inheritance  When a specialized class is instantiated, it calls the constructor on the specialized class.  The constructor is a special method that handles the initial setup of an object.  If it doesn’t find a valid one it will error, even if one exists in the parent.  Constructors can propagate invocations up the object hierarchy through the use of the MyBase keyword.  MyBase always refers to the parent object in VB .NET.  Easy to do, because each child has only one parent.  In a constructor, must always be the first method call.  Everywhere else, it can be anywhere.
  • 13. + Constructors  In VB .NET, a constructor is indicated by a subroutine called New: Public sub New() Me.Balance = 100 End Sub Public sub New (ByVal value as initialBalance) Me.Balance = initialBalance End Sub  We can overload these methods too.  And all methods in Visual Basic .NET.
  • 14. + Multiple Inheritance  The biggest distinction between C++ and .NET inheritance models is that C++ permits multiple inheritance.  Java, VB .NET and C# do not provide this.  It must be used extremely carefully.  If you are unsure what you are doing, it is tremendously easy to make a huge mess of a program.  It is in fact something best avoided.  Usually.  It’s not something you usually need.  There are usually better and less fragile ways of accomplishing a goal.
  • 15. + Multiple Inheritance  What are the problems with multiple inheritance?  Hugely increased program complexity  Problems with ambiguous function calls.  The Diamond Problem  Hardly ever really needed.  For simple applications, single inheritance suffices.  For more complicated situations, design patterns exist to resolve all the requirements.  Some languages permit multiple inheritance but resolve some of the technical issues.  These have relatively limited traction in the real world.
  • 16. + Specialisation and Extension  Inheritance by itself is not useful.  It gives us a version of what we already have.  It becomes useful because we then have three options with the things we get from a parent class.  We keep them as they are.  We specialise them to change them slightly.  We add to what we already have.  In this way we can ensure that our new classes are substantively different from the old classes.  And thus are a worthwhile addition to our system.
  • 17. + Specialisation  Specialisation means taking a behaviour and altering it.  We can override it completely  We can have it do something extra before passing it back to the method in the parent.  Whenever we provide a method with the same name in a child class, it is called overriding.  In VB .NET we must indicate our intention to override.  Other languages don’t require that.  When a method is overridden, the most specialised version of the method gets called when we invoke it.
  • 18. + Specialisation  Having overriden a method, we decide what happens next.  We either ignore the code that we inherited.  Or we pass the invocation ‘back up the chain’  Each overridden method is responsible for deciding what is to be done in that regard.  In Visual Basic .NET, we can refer to methods in a parent class through the MyBase keyword.  We saw that in relation to constructors a little earlier.  More on this later.  For now, it’s okay for our class diagrams to know this can be done.
  • 19. + Extension  With extension, we add to the attributes and behaviours we got from the parent.  We add new attributes  We add new methods  These let us give a wider range of functionality that we otherwise would have.  And let us branch out what our classes are for.  This works just the same way as we saw in the VB code example.  We just stick the new methods and attributes in there.
  • 20. + Inheritance  In our class tutorial, we had a Living class which was the parent of NPC and Player.  Both received the base functionality for representing an object which is considered to be ‘living’ in the game.  However, both had unique elements to go with them.  Likely many of the methods that we inherited would end up being overridden.  We’ll talk about that in the tutorial.  The inheritance allows us to share code rather than re- implement it.  This in turn reduces our future maintenance burden.
  • 21. + Conclusion  Inheritance is a powerful tool in object orientation.  One of the Great Trilogy of tools.  Encapsulation  Inheritance  Polymorphism.  VB .NET permits single inheritance only.  This will limit us, but only until we learn how to work around it.  Inheritance is only the start of the process.  It must then be followed through with specialisation and extension.