SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
MODELING AN OBJECT
ORIENTED PROGRAM
Michael Heron
Introduction
• In this lecture we are going to take a little detour into the
world of UML.
• A small detour, to support us in later weeks.
• UML is a language of diagrams and syntax designed to
communicate the intention and design of object oriented
programs.
• For our purpose, we are going to discuss only one part of
it.
• The Class Diagram
Class Diagrams
• One of the reasons why software development has such a
complex vocabulary of jargon is the need for experts to
communicate succinctly.
• This is what all formal software design techniques are about.
• It is extremely useful when we talk about the design of
objects for us to have some kind of shared vocabulary.
• Hence the introduction of this diagram.
Class Diagrams
• You won’t be expected during this module to be able to
break complex problems down into objects and classes of
your own.
• You’ll learn more about that in third year.
• All I would like of you with relation to class diagrams is
that you can read them and interpret them.
• And at a push, write up your own.
Object Oriented Programs
• Object oriented programs introduce new complexities of
interaction.
• Objects have a relationship to classes.
• Objects may be composed of other objects.
• Objects define their own behaviours and attributes.
• Objects can offer several levels of indirection to other objects.
• Gaining a clear perspective on how an object oriented
program fits together is key to developing and maintaining
OO code.
Object Relationships
• Objects can contain references to other objects.
• This is known as composition.
• This is a has a relationship.
• Composition relationships also imply a multiplicity (or
cardinality).
• Where there is a 0 or 1 relationship, it is known as a composition.
• Where it is more, it is an aggregation.
• Formal UML notations have more precise differentiations
of composition.
Object Relationships
• An object may be a specialisation of another object.
• This is known as inheritance in object orientation.
• This is a is a relationship.
• More specialised forms of inheritance exist.
• We’ll talk about these as we go along.
• For now, we will look only at the case that a class can
inherit the properties of another in their entirety.
Examples
• A Car:
• Has an engine (composition)
• Has four wheels (aggregation)
• Has 2 or more doors (aggregation)
• Is a vehicle (inheritance)
• A Cat:
• Has four legs (aggregation)
• Is an animal (inheritance)
• Has a tail (composition)
Object Oriented Programs
• The relationship between objects and classes becomes
very complex in many computer programs.
• Some means of representing this complexity ‘at a glance’
is useful.
• This is what a class diagram is used for.
• It gives the static view of a program’s architecture.
• Other techniques exist too.
• They vary in effectiveness.
Class Diagrams
• At their simplest, class diagrams are just boxes with lines
connecting them to other boxes.
• They show the relationship between classes only.
Class Diagrams
• At the next level of usefulness, class diagrams also
contain information about attributes and methods.
• Attributes in the second row
• Methods in the third
• At their best, class diagrams contain class relationships,
methods, attributes, and the visibility of each.
• They also explicitly show multiplicity.
Class Diagram with Attributes
Why Use A Class Diagram?
• There are several reasons why usig a class diagram
leads to a more complete view of a project.
• It shows the relationship between classes in a way that allows you
to trace accessibility.
• It shows at a glance the amount of coupling in a project.
• It shows at a glance the amount of cohesion in a project.
• It shows at a glance the impact of change.
Coupling and Cohesion
• One of the biggest problems OO developers have is
ensuring a good OO design.
• What is a good OO design, you ask?
• Certainly for people unfamiliar with how OO is best done,
it’s hard to objectively rate an object architecture.
• Two objective measures exist for this though.
• As a rule, we are aiming for high cohesion and low
coupling.
Coupling
• Coupling relates to the amount of interconnectedness of
classes.
• We want this to be as low as is reasonably possible.
• A coupling relationship is any composition, aggregation, or
inheritance.
• The more connections made between objects and classes, the
harder it is to make any changes.
• Because of the knock-on effect associated.
Coupling
• If your program has high coupling, there are several
disadvantages built in:
• Changes in one object may result in unexpected side-effects
elsewhere in a program.
• Often the cause is not at all obvious.
• Classes are difficult to understand at a glance.
• They make use of so much external functionality.
• Classes are difficult to test.
• They cannot be easily extracted from their context.
Coupling
• There are several types of coupling that exist.
• It’s not just the amount of coupling that matters, but also the type of coupling.
• Content coupling is when one class directly accesses data local to
another class.
• This is terrible and should be avoided always.
• Data coupling is when a public interface is used to exchange to
exchange parameters.
• This is better.
• There are other kinds.
• We don’t have to go into them to any great degree for now.
Cohesion
• Cohesion is the level to which an object adheres to a
single set of responsibilities.
• We want this as high as is reasonably possible.
• In a good object oriented program, each object has one
firmly defined responsibility.
• If you have a BankBalance class, it should contain only the
functionality for manipulating the balance.
• It should not contain, for example, the address of its owner.
Cohesion
• The dangers that come from low cohesion are the same as that
of high coupling.
• They’re really just two ways of reflecting the same basic concept.
• Low cohesion is an insidious problem.
• Programs with low cohesion tend to become even less coherent over
time.
• It is a consequence of badly analysed and badly designed
programs.
• You’ll learn how to do this properly in third year.
The Tension of OO Development
• Object Oriented programs are a tension between coupling
and cohesion.
• We increase cohesion by increasing coupling.
• We reduce coupling by decreasing cohesion.
• As OO developers we have to find a happy medium
between the two.
• In some cases, simple rationalisation of a design can remove
problems.
Impact of Change
• Both of these concepts are a way of objectively rating the
impact of change in a program.
• What makes a program easy to work with?
• Clearly written code.
• Comments (seriously)
• Changes do not have unexpected consequences.
• The latter of these three is what the impact of change
defines.
Impact of Change
• One of the reasons we restrict visibility of variables and
methods is to manage the impact of change.
• If you are a Respectful Developer, you avoid making changes that will
impact on code you did not write.
• Lest terrible vengeance be visited upon you and your kith and kin
• The lower the visibility, the better.
• Changing a private variable for example only impacts the class in
which it is defined.
Impact of Change
• In a multi-developer environment you have to assume that
if functionality is available, it has been used.
• Someone saw your calculate_awesome() method and thought ‘hey,
that does exactly what I want’
• If it can be used, you can’t idly make structural changes.
• Refactoring is fine
• Redesign is not
The Class Diagram
• The best quality of class diagrams shows the impact of
change at a glance.
• Where there are lots of arrows, there be coupling issues.
• Where there are huge lists of methods and attributes in a class,
there be likely cohesion problems.
• Where there are lots of public methods and attributes, there be
likely impact of change issues.
The Class Diagram
• In multi-developer projects, the class diagram represents
the ‘best understanding’ of how a program is being
developed.
• It’s kind of an informal contract with your fellow developers.
• One of the benefits we get from object orientation is an
easy of development and integration.
• But only if everyone is communicating effectively.
Summary
• Class diagrams are a useful shorthand notation for
classes.
• I tell you about them so you’ll know them when you see them.
• In addition, they help visualize certain structural problems
in object oriented program.
• Seeing the problems is the first step in resolving them of course.

Contenu connexe

Tendances (14)

Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software Engineering
 
UML Modeling in Java
UML Modeling in JavaUML Modeling in Java
UML Modeling in Java
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Designpattern
DesignpatternDesignpattern
Designpattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
2CPP01 - Intro to Module
2CPP01 - Intro to Module2CPP01 - Intro to Module
2CPP01 - Intro to Module
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
ooAD
ooADooAD
ooAD
 
Cs 1023 lec 9 design pattern (week 2)
Cs 1023 lec 9 design pattern (week 2)Cs 1023 lec 9 design pattern (week 2)
Cs 1023 lec 9 design pattern (week 2)
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
1Introduction to OOAD
1Introduction to OOAD1Introduction to OOAD
1Introduction to OOAD
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 

En vedette

En vedette (13)

Sample question format
Sample question formatSample question format
Sample question format
 
Object oriented modelling
Object oriented modellingObject oriented modelling
Object oriented modelling
 
Lect1
Lect1Lect1
Lect1
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case Diagram
 
Lecture04- Use Case Diagrams
Lecture04- Use Case DiagramsLecture04- Use Case Diagrams
Lecture04- Use Case Diagrams
 
Types of UML diagrams
Types of UML diagramsTypes of UML diagrams
Types of UML diagrams
 
UML- Unified Modeling Language
UML- Unified Modeling LanguageUML- Unified Modeling Language
UML- Unified Modeling Language
 
Uml - An Overview
Uml - An OverviewUml - An Overview
Uml - An Overview
 
Uml Presentation
Uml PresentationUml Presentation
Uml Presentation
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagrams
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case Diagram
 
Object Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UMLObject Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UML
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 

Similaire à 2CPP05 - Modelling an Object Oriented Program

CPP14 - Encapsulation
CPP14 - EncapsulationCPP14 - Encapsulation
CPP14 - EncapsulationMichael Heron
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object DesignMichael Heron
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - EncapsulationMichael Heron
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane1
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane2
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UMLSwatiS-BA
 
UML Training for Business Analysts
UML Training for Business AnalystsUML Training for Business Analysts
UML Training for Business AnalystsSwatiS-BA
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxanguraju1
 
SAD02 - Object Orientation
SAD02 - Object OrientationSAD02 - Object Orientation
SAD02 - Object OrientationMichael Heron
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptxUmerUmer25
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UMLVeneet-BA
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UMLVeneet-BA
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSkillwise Group
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxDrYogeshDeshmukh1
 
Ooad lab manual
Ooad  lab manualOoad  lab manual
Ooad lab manualPraseela R
 

Similaire à 2CPP05 - Modelling an Object Oriented Program (20)

CPP14 - Encapsulation
CPP14 - EncapsulationCPP14 - Encapsulation
CPP14 - Encapsulation
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object Design
 
2CPP09 - Encapsulation
2CPP09 - Encapsulation2CPP09 - Encapsulation
2CPP09 - Encapsulation
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
 
2CPP19 - Summation
2CPP19 - Summation2CPP19 - Summation
2CPP19 - Summation
 
UML constructs
UML constructs UML constructs
UML constructs
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
UML Training for Business Analysts
UML Training for Business AnalystsUML Training for Business Analysts
UML Training for Business Analysts
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
SAD02 - Object Orientation
SAD02 - Object OrientationSAD02 - Object Orientation
SAD02 - Object Orientation
 
Intro to oop.pptx
Intro to oop.pptxIntro to oop.pptx
Intro to oop.pptx
 
Design pattern - part 1
Design pattern - part 1Design pattern - part 1
Design pattern - part 1
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UML
 
Introduction to OOA and UML
Introduction to OOA and UMLIntroduction to OOA and UML
Introduction to OOA and UML
 
[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptx
 
Ooad lab manual
Ooad  lab manualOoad  lab manual
Ooad lab manual
 

Plus 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
 
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
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and AutershipMichael Heron
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interactionMichael 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
 

Plus de Michael Heron (20)

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
 
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
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interaction
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - Inheritance
 
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
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 

Dernier

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainAbdul Ahad
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Copilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotCopilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotEdgard Alejos
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 

Dernier (20)

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software Domain
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Copilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotCopilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform Copilot
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 

2CPP05 - Modelling an Object Oriented Program

  • 1. MODELING AN OBJECT ORIENTED PROGRAM Michael Heron
  • 2. Introduction • In this lecture we are going to take a little detour into the world of UML. • A small detour, to support us in later weeks. • UML is a language of diagrams and syntax designed to communicate the intention and design of object oriented programs. • For our purpose, we are going to discuss only one part of it. • The Class Diagram
  • 3. Class Diagrams • One of the reasons why software development has such a complex vocabulary of jargon is the need for experts to communicate succinctly. • This is what all formal software design techniques are about. • It is extremely useful when we talk about the design of objects for us to have some kind of shared vocabulary. • Hence the introduction of this diagram.
  • 4. Class Diagrams • You won’t be expected during this module to be able to break complex problems down into objects and classes of your own. • You’ll learn more about that in third year. • All I would like of you with relation to class diagrams is that you can read them and interpret them. • And at a push, write up your own.
  • 5. Object Oriented Programs • Object oriented programs introduce new complexities of interaction. • Objects have a relationship to classes. • Objects may be composed of other objects. • Objects define their own behaviours and attributes. • Objects can offer several levels of indirection to other objects. • Gaining a clear perspective on how an object oriented program fits together is key to developing and maintaining OO code.
  • 6. Object Relationships • Objects can contain references to other objects. • This is known as composition. • This is a has a relationship. • Composition relationships also imply a multiplicity (or cardinality). • Where there is a 0 or 1 relationship, it is known as a composition. • Where it is more, it is an aggregation. • Formal UML notations have more precise differentiations of composition.
  • 7. Object Relationships • An object may be a specialisation of another object. • This is known as inheritance in object orientation. • This is a is a relationship. • More specialised forms of inheritance exist. • We’ll talk about these as we go along. • For now, we will look only at the case that a class can inherit the properties of another in their entirety.
  • 8. Examples • A Car: • Has an engine (composition) • Has four wheels (aggregation) • Has 2 or more doors (aggregation) • Is a vehicle (inheritance) • A Cat: • Has four legs (aggregation) • Is an animal (inheritance) • Has a tail (composition)
  • 9. Object Oriented Programs • The relationship between objects and classes becomes very complex in many computer programs. • Some means of representing this complexity ‘at a glance’ is useful. • This is what a class diagram is used for. • It gives the static view of a program’s architecture. • Other techniques exist too. • They vary in effectiveness.
  • 10. Class Diagrams • At their simplest, class diagrams are just boxes with lines connecting them to other boxes. • They show the relationship between classes only.
  • 11. Class Diagrams • At the next level of usefulness, class diagrams also contain information about attributes and methods. • Attributes in the second row • Methods in the third • At their best, class diagrams contain class relationships, methods, attributes, and the visibility of each. • They also explicitly show multiplicity.
  • 12. Class Diagram with Attributes
  • 13. Why Use A Class Diagram? • There are several reasons why usig a class diagram leads to a more complete view of a project. • It shows the relationship between classes in a way that allows you to trace accessibility. • It shows at a glance the amount of coupling in a project. • It shows at a glance the amount of cohesion in a project. • It shows at a glance the impact of change.
  • 14. Coupling and Cohesion • One of the biggest problems OO developers have is ensuring a good OO design. • What is a good OO design, you ask? • Certainly for people unfamiliar with how OO is best done, it’s hard to objectively rate an object architecture. • Two objective measures exist for this though. • As a rule, we are aiming for high cohesion and low coupling.
  • 15. Coupling • Coupling relates to the amount of interconnectedness of classes. • We want this to be as low as is reasonably possible. • A coupling relationship is any composition, aggregation, or inheritance. • The more connections made between objects and classes, the harder it is to make any changes. • Because of the knock-on effect associated.
  • 16. Coupling • If your program has high coupling, there are several disadvantages built in: • Changes in one object may result in unexpected side-effects elsewhere in a program. • Often the cause is not at all obvious. • Classes are difficult to understand at a glance. • They make use of so much external functionality. • Classes are difficult to test. • They cannot be easily extracted from their context.
  • 17. Coupling • There are several types of coupling that exist. • It’s not just the amount of coupling that matters, but also the type of coupling. • Content coupling is when one class directly accesses data local to another class. • This is terrible and should be avoided always. • Data coupling is when a public interface is used to exchange to exchange parameters. • This is better. • There are other kinds. • We don’t have to go into them to any great degree for now.
  • 18. Cohesion • Cohesion is the level to which an object adheres to a single set of responsibilities. • We want this as high as is reasonably possible. • In a good object oriented program, each object has one firmly defined responsibility. • If you have a BankBalance class, it should contain only the functionality for manipulating the balance. • It should not contain, for example, the address of its owner.
  • 19. Cohesion • The dangers that come from low cohesion are the same as that of high coupling. • They’re really just two ways of reflecting the same basic concept. • Low cohesion is an insidious problem. • Programs with low cohesion tend to become even less coherent over time. • It is a consequence of badly analysed and badly designed programs. • You’ll learn how to do this properly in third year.
  • 20. The Tension of OO Development • Object Oriented programs are a tension between coupling and cohesion. • We increase cohesion by increasing coupling. • We reduce coupling by decreasing cohesion. • As OO developers we have to find a happy medium between the two. • In some cases, simple rationalisation of a design can remove problems.
  • 21. Impact of Change • Both of these concepts are a way of objectively rating the impact of change in a program. • What makes a program easy to work with? • Clearly written code. • Comments (seriously) • Changes do not have unexpected consequences. • The latter of these three is what the impact of change defines.
  • 22. Impact of Change • One of the reasons we restrict visibility of variables and methods is to manage the impact of change. • If you are a Respectful Developer, you avoid making changes that will impact on code you did not write. • Lest terrible vengeance be visited upon you and your kith and kin • The lower the visibility, the better. • Changing a private variable for example only impacts the class in which it is defined.
  • 23. Impact of Change • In a multi-developer environment you have to assume that if functionality is available, it has been used. • Someone saw your calculate_awesome() method and thought ‘hey, that does exactly what I want’ • If it can be used, you can’t idly make structural changes. • Refactoring is fine • Redesign is not
  • 24. The Class Diagram • The best quality of class diagrams shows the impact of change at a glance. • Where there are lots of arrows, there be coupling issues. • Where there are huge lists of methods and attributes in a class, there be likely cohesion problems. • Where there are lots of public methods and attributes, there be likely impact of change issues.
  • 25. The Class Diagram • In multi-developer projects, the class diagram represents the ‘best understanding’ of how a program is being developed. • It’s kind of an informal contract with your fellow developers. • One of the benefits we get from object orientation is an easy of development and integration. • But only if everyone is communicating effectively.
  • 26. Summary • Class diagrams are a useful shorthand notation for classes. • I tell you about them so you’ll know them when you see them. • In addition, they help visualize certain structural problems in object oriented program. • Seeing the problems is the first step in resolving them of course.