SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
Object Oriented Metrics

    How should we judge code?

●   1994 - Chidamber & Kemerer
●   A Metrics suite for Object Oriented design
What did they say?
WMC Weighted Methods Per Class
DIT   Depth of Inheritance Tree
NOC   Number of Children
CBO   Coupling between Object Classes
RFC   Response for a Class
LCOM Lack of Cohesion of Methods
Weighted Methods Per Class
        Number of methods defined in class

●   Complex methods weigh more
●   Higher numbers = more faults
●   Classes are more specific = hard to reuse
●   Changes have more impact on subclasses


    20-40 methods; 10% of classes > 24
Depth of Inheritance Tree
                Number of superclasses

●   Measures depth of hierarchy
●   Deep trees imply more complexity
●   Inheritance should reduce complexity not increase it
●   Deep trees promote reuse
●   Bugs are found in middle of tree


    5 or less; some say 8 or less
Number of Children
          Number of immediate subclasses

●   Measures breadth of hierarchy
●   Depth (DIT) implies reuse in a way breath (NOC) does not
●   Large numbers mean high reuse of base class; test it!
●   High NOC related to lower faults.
●   BUT, perhaps improper use of base class


    High NOC + high WMC; complexity at top
Coupling between Object Classes
     Number of classes to which I am coupled

●   Coupling → We use each others data or methods
●   High CBO is undesirable
●   Prevents reuse
●   Sensitivity to changes in others increases maintenance


    > 14 is too high
Response For a Class
         Total number of methods executed

●   Large RFC = more faults
●   If most methods have a small RFC but one method has a
       hugh RFC
    → you have a structured (not OO) application


    Concentrate tests on high RFC methods
Lack of Cohesion of Methods
     How well are the methods of a class are
              related to each other?

●   A cohesive class performs one function
●   Highly cohesive classes promotes encapsulation
    but have highly coupled methods
●   Low cohesion = more errors


    Measured by checking use of instance vars
Does these really matter?
    Research says they do:

●   1995 - Victor Basili, etc – University of Maryland
●   A Validation of Object-Oriented Design
      Metrics

●   2001 – Victor Laing – SATC study at NASA
●   Principal Components of Orthogonal
      Object-Oriented Metrics
NASA Study
●   A - Java. 50K LOC, 46 classes, lowq
●   B - Java, 300k LOC, 1,000 classes, highq
●   C - C++, 500K LOC, 1,617 classes, mediumq


    Result: Bad metrics = faulty applications
A metric of your own

●   http://metric-fu.rubyforge.org/

●   http://getcaliper.com/
metric_fu

●   Saikuro, Flog → complexity
●   Flay          → duplication
●   Roodi, Reek   → code smells
Using metric_fu
Gemfile . . .
   group :test do
     gem 'cucumber', '0.4.3'
     ...
     gem 'metric_fu', '1.3.0'
     gem 'reek'
     gem 'roodi'
     gem 'googlecharts'
    end
Using metric_fu

In → lib/tasks/metric_fu.rake


  require 'metric_fu'
  config from
    http://metric-fu.rubyforge.org/
Using metric_fu

●   bundle install

●   bundle exec rake metrics:all
Let's go have a look
What should you do?
●   Run metric_fu on your new apps
      get insight into the choices you're making
      keep yourself honest


●   Run metric_fu on existing apps
      concentrate testing at boundaries of suspect code
      protect yourself
References
●   http://www.pitt.edu/~ckemerer/CK research
      papers/MetricForOOD_ChidamberKemerer94.pdf       .




●   http://www.cs.umd.edu/users/basili/publications/journals/
      J60.pdf .




●   http://satc.gsfc.nasa.gov/support/OSMASAS_SEP01/Princip
      al_Components_of_Orthogonal_Object_Oriented_Met
      rics.pdf    .




●   http://www.aivosto.com/project/help/pm-oo-ck.html      .

Mais conteúdo relacionado

Mais procurados

Software development slides
Software development slidesSoftware development slides
Software development slides
iarthur
 

Mais procurados (20)

Software engineering : Layered Architecture
Software engineering : Layered ArchitectureSoftware engineering : Layered Architecture
Software engineering : Layered Architecture
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
Cohesion and coupling
Cohesion and couplingCohesion and coupling
Cohesion and coupling
 
Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software Coding
 
Software Evolution
Software EvolutionSoftware Evolution
Software Evolution
 
Unified process model
Unified process modelUnified process model
Unified process model
 
Unit 5- Architectural Design in software engineering
Unit 5- Architectural Design in software engineering Unit 5- Architectural Design in software engineering
Unit 5- Architectural Design in software engineering
 
Data Designs (Software Engg.)
Data Designs (Software Engg.)Data Designs (Software Engg.)
Data Designs (Software Engg.)
 
Cocomo model
Cocomo modelCocomo model
Cocomo model
 
Designing Techniques in Software Engineering
Designing Techniques in Software EngineeringDesigning Techniques in Software Engineering
Designing Techniques in Software Engineering
 
Software development process models
Software development process modelsSoftware development process models
Software development process models
 
Sdlc
SdlcSdlc
Sdlc
 
Agile development, software engineering
Agile development, software engineeringAgile development, software engineering
Agile development, software engineering
 
Fundamental design concepts
Fundamental design conceptsFundamental design concepts
Fundamental design concepts
 
Introduction to Software Engineering
Introduction to Software EngineeringIntroduction to Software Engineering
Introduction to Software Engineering
 
Artificial Intelligence: Knowledge Acquisition
Artificial Intelligence: Knowledge AcquisitionArtificial Intelligence: Knowledge Acquisition
Artificial Intelligence: Knowledge Acquisition
 
Advanced behavioral modeling chapter 4 of omd
Advanced behavioral modeling chapter 4 of omdAdvanced behavioral modeling chapter 4 of omd
Advanced behavioral modeling chapter 4 of omd
 
Spm software effort estimation
Spm software effort estimationSpm software effort estimation
Spm software effort estimation
 
Software development slides
Software development slidesSoftware development slides
Software development slides
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case Diagram
 

Semelhante a OO Metrics

Revisiting the Notion of Diversity in Software Testing
Revisiting the Notion of Diversity in Software TestingRevisiting the Notion of Diversity in Software Testing
Revisiting the Notion of Diversity in Software Testing
Lionel Briand
 
Algorithm ExampleFor the following taskUse the random module .docx
Algorithm ExampleFor the following taskUse the random module .docxAlgorithm ExampleFor the following taskUse the random module .docx
Algorithm ExampleFor the following taskUse the random module .docx
daniahendric
 

Semelhante a OO Metrics (20)

Triantafyllia Voulibasi
Triantafyllia VoulibasiTriantafyllia Voulibasi
Triantafyllia Voulibasi
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
 
Revisiting the Notion of Diversity in Software Testing
Revisiting the Notion of Diversity in Software TestingRevisiting the Notion of Diversity in Software Testing
Revisiting the Notion of Diversity in Software Testing
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.
 
Webinar: How We Evaluated MongoDB as a Relational Database Replacement
Webinar: How We Evaluated MongoDB as a Relational Database ReplacementWebinar: How We Evaluated MongoDB as a Relational Database Replacement
Webinar: How We Evaluated MongoDB as a Relational Database Replacement
 
The End-to-End Use of Source Code Example: An Exploratory Study ICSM'09
The End-to-End Use of Source Code Example: An Exploratory Study  ICSM'09The End-to-End Use of Source Code Example: An Exploratory Study  ICSM'09
The End-to-End Use of Source Code Example: An Exploratory Study ICSM'09
 
Code quality
Code quality Code quality
Code quality
 
GatlingJAX2022.pdf
GatlingJAX2022.pdfGatlingJAX2022.pdf
GatlingJAX2022.pdf
 
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
 
Design for Testability
Design for Testability Design for Testability
Design for Testability
 
[243] Deep Learning to help student’s Deep Learning
[243] Deep Learning to help student’s Deep Learning[243] Deep Learning to help student’s Deep Learning
[243] Deep Learning to help student’s Deep Learning
 
How to improve your unit tests?
How to improve your unit tests?How to improve your unit tests?
How to improve your unit tests?
 
Algorithm ExampleFor the following taskUse the random module .docx
Algorithm ExampleFor the following taskUse the random module .docxAlgorithm ExampleFor the following taskUse the random module .docx
Algorithm ExampleFor the following taskUse the random module .docx
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
 
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
 
tmptmptmp123.pptx
tmptmptmp123.pptxtmptmptmp123.pptx
tmptmptmp123.pptx
 
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

OO Metrics

  • 1. Object Oriented Metrics How should we judge code? ● 1994 - Chidamber & Kemerer ● A Metrics suite for Object Oriented design
  • 2. What did they say? WMC Weighted Methods Per Class DIT Depth of Inheritance Tree NOC Number of Children CBO Coupling between Object Classes RFC Response for a Class LCOM Lack of Cohesion of Methods
  • 3. Weighted Methods Per Class Number of methods defined in class ● Complex methods weigh more ● Higher numbers = more faults ● Classes are more specific = hard to reuse ● Changes have more impact on subclasses 20-40 methods; 10% of classes > 24
  • 4. Depth of Inheritance Tree Number of superclasses ● Measures depth of hierarchy ● Deep trees imply more complexity ● Inheritance should reduce complexity not increase it ● Deep trees promote reuse ● Bugs are found in middle of tree 5 or less; some say 8 or less
  • 5. Number of Children Number of immediate subclasses ● Measures breadth of hierarchy ● Depth (DIT) implies reuse in a way breath (NOC) does not ● Large numbers mean high reuse of base class; test it! ● High NOC related to lower faults. ● BUT, perhaps improper use of base class High NOC + high WMC; complexity at top
  • 6. Coupling between Object Classes Number of classes to which I am coupled ● Coupling → We use each others data or methods ● High CBO is undesirable ● Prevents reuse ● Sensitivity to changes in others increases maintenance > 14 is too high
  • 7. Response For a Class Total number of methods executed ● Large RFC = more faults ● If most methods have a small RFC but one method has a hugh RFC → you have a structured (not OO) application Concentrate tests on high RFC methods
  • 8. Lack of Cohesion of Methods How well are the methods of a class are related to each other? ● A cohesive class performs one function ● Highly cohesive classes promotes encapsulation but have highly coupled methods ● Low cohesion = more errors Measured by checking use of instance vars
  • 9. Does these really matter? Research says they do: ● 1995 - Victor Basili, etc – University of Maryland ● A Validation of Object-Oriented Design Metrics ● 2001 – Victor Laing – SATC study at NASA ● Principal Components of Orthogonal Object-Oriented Metrics
  • 10. NASA Study ● A - Java. 50K LOC, 46 classes, lowq ● B - Java, 300k LOC, 1,000 classes, highq ● C - C++, 500K LOC, 1,617 classes, mediumq Result: Bad metrics = faulty applications
  • 11. A metric of your own ● http://metric-fu.rubyforge.org/ ● http://getcaliper.com/
  • 12. metric_fu ● Saikuro, Flog → complexity ● Flay → duplication ● Roodi, Reek → code smells
  • 13. Using metric_fu Gemfile . . . group :test do gem 'cucumber', '0.4.3' ... gem 'metric_fu', '1.3.0' gem 'reek' gem 'roodi' gem 'googlecharts' end
  • 14. Using metric_fu In → lib/tasks/metric_fu.rake require 'metric_fu' config from http://metric-fu.rubyforge.org/
  • 15. Using metric_fu ● bundle install ● bundle exec rake metrics:all
  • 16. Let's go have a look
  • 17. What should you do? ● Run metric_fu on your new apps get insight into the choices you're making keep yourself honest ● Run metric_fu on existing apps concentrate testing at boundaries of suspect code protect yourself
  • 18. References ● http://www.pitt.edu/~ckemerer/CK research papers/MetricForOOD_ChidamberKemerer94.pdf . ● http://www.cs.umd.edu/users/basili/publications/journals/ J60.pdf . ● http://satc.gsfc.nasa.gov/support/OSMASAS_SEP01/Princip al_Components_of_Orthogonal_Object_Oriented_Met rics.pdf . ● http://www.aivosto.com/project/help/pm-oo-ck.html .