SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere ähnliche Inhalte

Was ist angesagt?

Collaboration diagram- UML diagram
Collaboration diagram- UML diagram Collaboration diagram- UML diagram
Collaboration diagram- UML diagram Ramakant Soni
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)MD Sulaiman
 
UML (Unified Modeling Language)
UML (Unified Modeling Language)UML (Unified Modeling Language)
UML (Unified Modeling Language)Nguyen Tuan
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
Sequence diagram- UML diagram
Sequence diagram- UML diagramSequence diagram- UML diagram
Sequence diagram- UML diagramRamakant Soni
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
Data compression huffman coding algoritham
Data compression huffman coding algorithamData compression huffman coding algoritham
Data compression huffman coding algorithamRahul Khanwani
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming ConceptsKwangshin Oh
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
Raster animation
Raster animationRaster animation
Raster animationabhijit754
 
WebGL Fundamentals
WebGL FundamentalsWebGL Fundamentals
WebGL FundamentalsSencha
 
Activity diagram tutorial
Activity diagram tutorialActivity diagram tutorial
Activity diagram tutorialDeclan Chellar
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 

Was ist angesagt? (20)

Collaboration diagram- UML diagram
Collaboration diagram- UML diagram Collaboration diagram- UML diagram
Collaboration diagram- UML diagram
 
Class Diagram
Class DiagramClass Diagram
Class Diagram
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
UML (Unified Modeling Language)
UML (Unified Modeling Language)UML (Unified Modeling Language)
UML (Unified Modeling Language)
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Uml introduciton
Uml introducitonUml introduciton
Uml introduciton
 
Sequence diagram- UML diagram
Sequence diagram- UML diagramSequence diagram- UML diagram
Sequence diagram- UML diagram
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Data compression huffman coding algoritham
Data compression huffman coding algorithamData compression huffman coding algoritham
Data compression huffman coding algoritham
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming Concepts
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Uml class-diagram
Uml class-diagramUml class-diagram
Uml class-diagram
 
Raster animation
Raster animationRaster animation
Raster animation
 
WebGL Fundamentals
WebGL FundamentalsWebGL Fundamentals
WebGL Fundamentals
 
Activity diagram tutorial
Activity diagram tutorialActivity diagram tutorial
Activity diagram tutorial
 
Class diagram
Class diagramClass diagram
Class diagram
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 

Andere mochten auch

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
 

Andere mochten auch (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)
 

Ähnlich wie 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
 

Ähnlich wie 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
 
Oops in vb
Oops in vbOops in vb
Oops in vb
 
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
 
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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 

Kürzlich hochgeladen (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 

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.