SlideShare uma empresa Scribd logo
1 de 16
COMP23420 week 4:
    GRASP design principles (1)

   John Sargeant (johns@cs.man.ac.uk)

Please remember to switch off all electronic
         devices when in lectures.
Aspects of SE

3. Building the right software
4. Building the software right



Most of the course so far has been about 1. Now we will
  focus on 2.
Refactoring
• Most non-trivial SW systems end up as Big Balls of
  Mud – see http://www.laputan.org/mud/
• OO techniques help, up to a point, but don’t solve the
  problem
• Subsystems interact in unpredictable ways
• A design which looks good initially may be unsuitable
  later.
• Refactoring – changing the code purely to improve
  the design – is vital.
• Never refactor and add/change functionality at the
  same time.
GRASP
• How do we know what’s a good design?
• Only by experience, but much of that experience has
  recently been codified as Patterns.
• GRASP = General Responsibility Assignment
  Software Patterns
• A set of principles for assigning responsibilities to
  classes – the key skill in OO software design
  (observation: even strong programmers are often
  weak designers)
• GRASP provides the “building blocks” for Design
  Patterns (COMP33411)
Case study

You have been hired to develop an integrated
  information system for the Irwell online store. They
  originated as a book store but now sell other forms of
  media such as CDs and DVDs. They also intend to
  branch out into selling electronic devices such as
  laptops and PDAs although they don’t intend to
  become a general store.

Initially you will develop an inventory system: an
   inventory lists the products a company has in stock,
   along with information such as prices.
A possible design
Cohesion and coupling
• The most fundamental design principles of all
• High Cohesion: a class must represent a single well-
  defined entity
• Low coupling: minimise dependencies between
  classes
• NB: coupling is not just the number of connections
  between classes – how complex those connections
  are is also important
• The Inventory system class has very poor cohesion
  – it represents at least three different entities.
Types of coupling

• Internal coupling – between classes within a
  subsystem
• External coupling – between the subsystem and the
  rest of the system

The naïve design has high (i.e. bad) external coupling, a
  “bloated interface”.
Slightly better
Improvements
• Much better cohesion, each class is at least all one
  kind of thing.
• The UI is separated from the business logic – model-
  view separation.
• External coupling is reduced, e.g. code dealing with
  the inventory is not coupled to the UI.
• The UI and the Inventory, (and maybe the database
  interface) need to be decomposed further.
• UIs should be divided into small components each
  with a well-defined role. Avoid huge constructors and
  GridBagLayouts where possible.
Pure fabrication
A Pure fabrication is a design class which does not
  correspond to anything in the domain, e.g.
• Collections
• Interfaces to external systems, e.g. database
  connectors
• Factories – classes whose sole job is to create
  objects of other classes.
• UI components
• Indirections to, and abstractions of, other classes.
Over time, the PFs usually outnumber the domain-
  inspired classes.
Decomposing the Inventory

• A possible implementation has three lists, of
  products, prices, and numbers in stock.
• These have to be kept consistent.
• When this happens, it usually means we are missing
  something.
• In this case a line item, a (product, price, number)
  combination.
• Also, we should represent products as instances of a
  Product class.
A workable design
Why a separate Product class?
• We could have product information as part of the
  LineItem class, but
• Product is a logically separate concept – make it
  separate for this reason alone.
• It could appear in other parts of the application
• We can change the product implementation without
  affecting LineItem
• We may want to have different kinds of product – see
  next week.
• Note the multiplicity – a product can appear in more
  than one LineItem.
Information Expert
• GRASP principle – put a responsibility in the class
  which has the information to carry out that
  responsibility. (Often abbreviated to Expert)
• E.g. getTotalValue is in LineItem as it has the unit
  price and number-in-stock information.
• c.f. Don’t talk to strangers – avoid long chains of
  thing().thing().thing()….
• Converse – put the information needed for an
  operation in the class where that operation naturally
  fits.
To think about
• How could the LineItem class be reused elsewhere in
  the application?
• Why is the multiplicity: Product 1 -> 1..* LineItem
  (Hint when considering multiplicities always look at
  both ends, so this question has two answers)?
• Why is the unit price information in LineItem rather
  than Product?
• What information in the case study have we yet to
  take account of?
• How could your design for iteration 1 be improved in
  terms of coupling and cohesion?

Mais conteúdo relacionado

Destaque

Performance assessment using grasps
Performance assessment  using graspsPerformance assessment  using grasps
Performance assessment using grasps
Shyne De Vera
 
Assessment in the affective domain. cha.4.ed8
Assessment in the affective domain. cha.4.ed8Assessment in the affective domain. cha.4.ed8
Assessment in the affective domain. cha.4.ed8
Eddie Abug
 

Destaque (8)

GRASP Principles
GRASP PrinciplesGRASP Principles
GRASP Principles
 
Standards based assessment and grading in the k-12 system
Standards based assessment and grading in the k-12 systemStandards based assessment and grading in the k-12 system
Standards based assessment and grading in the k-12 system
 
Real World & Performance Assessment
Real World & Performance AssessmentReal World & Performance Assessment
Real World & Performance Assessment
 
Performance assessment using grasps
Performance assessment  using graspsPerformance assessment  using grasps
Performance assessment using grasps
 
Grasp task - 3
Grasp task - 3Grasp task - 3
Grasp task - 3
 
Assessment in the affective domain. cha.4.ed8
Assessment in the affective domain. cha.4.ed8Assessment in the affective domain. cha.4.ed8
Assessment in the affective domain. cha.4.ed8
 
english-grammar
english-grammarenglish-grammar
english-grammar
 
Writing present performance_(samples)
Writing present performance_(samples)Writing present performance_(samples)
Writing present performance_(samples)
 

Semelhante a Week4 grasp-into

Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5
Sudarshan Dhondaley
 

Semelhante a Week4 grasp-into (20)

Week5 inhertiance
Week5 inhertianceWeek5 inhertiance
Week5 inhertiance
 
Week3 to-design
Week3 to-designWeek3 to-design
Week3 to-design
 
Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5
 
OOP -interface and objects.pptx
OOP -interface and objects.pptxOOP -interface and objects.pptx
OOP -interface and objects.pptx
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
Software Engineering Lec 8-design-
Software Engineering Lec 8-design-Software Engineering Lec 8-design-
Software Engineering Lec 8-design-
 
Software Eng S3 ( Software Design ).pptx
Software Eng S3 ( Software Design ).pptxSoftware Eng S3 ( Software Design ).pptx
Software Eng S3 ( Software Design ).pptx
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
Architecture presentation 4
Architecture presentation 4Architecture presentation 4
Architecture presentation 4
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
 
CPP16 - Object Design
CPP16 - Object DesignCPP16 - Object Design
CPP16 - Object Design
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
Patterns of enterprise application architecture
Patterns of enterprise application architecturePatterns of enterprise application architecture
Patterns of enterprise application architecture
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedArchitecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons Learned
 
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
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
 
1605162990-week56.pptx
1605162990-week56.pptx1605162990-week56.pptx
1605162990-week56.pptx
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Week4 grasp-into

  • 1. COMP23420 week 4: GRASP design principles (1) John Sargeant (johns@cs.man.ac.uk) Please remember to switch off all electronic devices when in lectures.
  • 2. Aspects of SE 3. Building the right software 4. Building the software right Most of the course so far has been about 1. Now we will focus on 2.
  • 3. Refactoring • Most non-trivial SW systems end up as Big Balls of Mud – see http://www.laputan.org/mud/ • OO techniques help, up to a point, but don’t solve the problem • Subsystems interact in unpredictable ways • A design which looks good initially may be unsuitable later. • Refactoring – changing the code purely to improve the design – is vital. • Never refactor and add/change functionality at the same time.
  • 4. GRASP • How do we know what’s a good design? • Only by experience, but much of that experience has recently been codified as Patterns. • GRASP = General Responsibility Assignment Software Patterns • A set of principles for assigning responsibilities to classes – the key skill in OO software design (observation: even strong programmers are often weak designers) • GRASP provides the “building blocks” for Design Patterns (COMP33411)
  • 5. Case study You have been hired to develop an integrated information system for the Irwell online store. They originated as a book store but now sell other forms of media such as CDs and DVDs. They also intend to branch out into selling electronic devices such as laptops and PDAs although they don’t intend to become a general store. Initially you will develop an inventory system: an inventory lists the products a company has in stock, along with information such as prices.
  • 7. Cohesion and coupling • The most fundamental design principles of all • High Cohesion: a class must represent a single well- defined entity • Low coupling: minimise dependencies between classes • NB: coupling is not just the number of connections between classes – how complex those connections are is also important • The Inventory system class has very poor cohesion – it represents at least three different entities.
  • 8. Types of coupling • Internal coupling – between classes within a subsystem • External coupling – between the subsystem and the rest of the system The naïve design has high (i.e. bad) external coupling, a “bloated interface”.
  • 10. Improvements • Much better cohesion, each class is at least all one kind of thing. • The UI is separated from the business logic – model- view separation. • External coupling is reduced, e.g. code dealing with the inventory is not coupled to the UI. • The UI and the Inventory, (and maybe the database interface) need to be decomposed further. • UIs should be divided into small components each with a well-defined role. Avoid huge constructors and GridBagLayouts where possible.
  • 11. Pure fabrication A Pure fabrication is a design class which does not correspond to anything in the domain, e.g. • Collections • Interfaces to external systems, e.g. database connectors • Factories – classes whose sole job is to create objects of other classes. • UI components • Indirections to, and abstractions of, other classes. Over time, the PFs usually outnumber the domain- inspired classes.
  • 12. Decomposing the Inventory • A possible implementation has three lists, of products, prices, and numbers in stock. • These have to be kept consistent. • When this happens, it usually means we are missing something. • In this case a line item, a (product, price, number) combination. • Also, we should represent products as instances of a Product class.
  • 14. Why a separate Product class? • We could have product information as part of the LineItem class, but • Product is a logically separate concept – make it separate for this reason alone. • It could appear in other parts of the application • We can change the product implementation without affecting LineItem • We may want to have different kinds of product – see next week. • Note the multiplicity – a product can appear in more than one LineItem.
  • 15. Information Expert • GRASP principle – put a responsibility in the class which has the information to carry out that responsibility. (Often abbreviated to Expert) • E.g. getTotalValue is in LineItem as it has the unit price and number-in-stock information. • c.f. Don’t talk to strangers – avoid long chains of thing().thing().thing()…. • Converse – put the information needed for an operation in the class where that operation naturally fits.
  • 16. To think about • How could the LineItem class be reused elsewhere in the application? • Why is the multiplicity: Product 1 -> 1..* LineItem (Hint when considering multiplicities always look at both ends, so this question has two answers)? • Why is the unit price information in LineItem rather than Product? • What information in the case study have we yet to take account of? • How could your design for iteration 1 be improved in terms of coupling and cohesion?

Notas do Editor

  1. Title slide