SlideShare uma empresa Scribd logo
1 de 15
Design by Contract




                               Jiří Kiml,
                               18/08/2011, Bern



www.querity.cz
Agenda

            ►Motivation
            ►DBC
            ►Support in JAVA
            ►Eclipse examples
            ►Summary
            ►Links




www.querity.cz
Motivation

       Always code as if the guy who ends up maintaining
       your code will be a violent psychopath who knows
       where you live.
       ~Martin Golding


       ►Wouldn't it be nice if all Java classes that you
        use, including your own, lived up to their
        promises?



www.querity.cz
Design by Contract (1)
      ►The Design by Contract (DBC) software
       development technique ensures high-
       quality software by guaranteeing that every
       component of a system lives up to its
       expectations. As a developer using DBC,
       you specify component contracts as part of
       the component's interface. The contract
       specifies what that component expects of
       clients and what clients can expect of it.
     ►Bertrand Meyer developed DBC as part of
      his Eiffel programming language.
      Regardless of its origin, DBC is a valuable
      design technique for all programming
      languages, including Java.
www.querity.cz
Design by Contract (2)
   ►Central to DBC is the notion of an assertion
   ►At runtime we evaluate the assertions at
    specific checkpoints during the system's
    execution.




www.querity.cz
Kinds of Assert expressions
      ►Preconditions
      ►Postconditions
      ►Invariants




www.querity.cz
Preconditions
 ►Preconditions specify conditions that
  must hold before a method can execute.
  As such, they are evaluated just before a
  method executes. Preconditions involve
  the system state and the arguments
  passed into the method.
 ►Preconditions specify obligations that a
  client of a software component must
  meet before it may invoke a particular
  method of the component.
 ►If a precondition fails, a bug is in a
  software component's client.


www.querity.cz
Postconditions
   ►In contrast, postconditions specify
    conditions that must hold after a method
    completes. Consequently, postconditions
    are executed after a method completes.
    Postconditions involve the old system
    state, the new system state, the method
    arguments, and the method's return
    value.
   ►Postconditions specify guarantees that a
    software component makes to its clients.
    If a postcondition is violated, the
    software component has a bug.


www.querity.cz
Invariants
   ►An invariant specifies a condition that
    must hold any time a client could invoke
    an object's method. Invariants are
    defined as part of a class definition. In
    practice, invariants are evaluated any
    time before and after a method on any
    class instance executes. A violation of an
    invariant may indicate a bug in either the
    client or the software component.




www.querity.cz
Support in JAVA
   ►Assert keyword
   ►Many third party solutions
    (annotations, AspectJ)
   ►DBC class




www.querity.cz
Eclipse examples
   ► XXXX




www.querity.cz
Summary

     ►Contracts in code are good
     ►Easy to use
     ►Correctness
     ►Robustness




www.querity.cz
Links
    ►Two presentations:
      – http://www.eiffel.com/developers/presentations/
    ►http://en.wikipedia.org/wiki/Design_by_con
     tract




www.querity.cz
Questions …
    … and maybe answers




www.querity.cz
Thank you



                        Jiří Kiml ,
                        18/08/2011, Bern




www.querity.cz

Mais conteúdo relacionado

Mais procurados

Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code first
Confiz
 
Chuyen de luong giac 1 www.mathvn.com
Chuyen de luong giac 1   www.mathvn.comChuyen de luong giac 1   www.mathvn.com
Chuyen de luong giac 1 www.mathvn.com
hoabanglanglk
 

Mais procurados (20)

Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code first
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Java threading
Java threadingJava threading
Java threading
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Spring jdbc dao
Spring jdbc daoSpring jdbc dao
Spring jdbc dao
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkers
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Structural patterns
Structural patternsStructural patterns
Structural patterns
 
Δομή Επανάληψης
Δομή ΕπανάληψηςΔομή Επανάληψης
Δομή Επανάληψης
 
Επαναληπτική άσκηση Β Λυκείου Κατεύθυνσης
Επαναληπτική άσκηση Β Λυκείου ΚατεύθυνσηςΕπαναληπτική άσκηση Β Λυκείου Κατεύθυνσης
Επαναληπτική άσκηση Β Λυκείου Κατεύθυνσης
 
Exception handling in ASP .NET
Exception handling in ASP .NETException handling in ASP .NET
Exception handling in ASP .NET
 
int 21,16,09 h
int 21,16,09 hint 21,16,09 h
int 21,16,09 h
 
Corba
CorbaCorba
Corba
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Producer consumer
Producer consumerProducer consumer
Producer consumer
 
BT giải pt, hpt lớp 10
BT giải pt, hpt lớp 10BT giải pt, hpt lớp 10
BT giải pt, hpt lớp 10
 
Introduction to Database Management Systems
Introduction to Database Management SystemsIntroduction to Database Management Systems
Introduction to Database Management Systems
 
Chuyen de luong giac 1 www.mathvn.com
Chuyen de luong giac 1   www.mathvn.comChuyen de luong giac 1   www.mathvn.com
Chuyen de luong giac 1 www.mathvn.com
 
Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4
 

Semelhante a Design by contract

How to build a proper software staging environment for testing
How to build a proper software staging environment for testing How to build a proper software staging environment for testing
How to build a proper software staging environment for testing
TestCampRO
 
Clean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampClean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code Camp
Theo Jungeblut
 
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian GötzingerMASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
Ievgenii Katsan
 
Close encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet CodeClose encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet Code
lbergmans
 
Close Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet codeClose Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet code
lbergmans
 

Semelhante a Design by contract (20)

The Zen of Inversion of Control
The Zen of Inversion of ControlThe Zen of Inversion of Control
The Zen of Inversion of Control
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
How to build a proper software staging environment for testing
How to build a proper software staging environment for testing How to build a proper software staging environment for testing
How to build a proper software staging environment for testing
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
 
Mocking vtcc3 - en
Mocking   vtcc3 - enMocking   vtcc3 - en
Mocking vtcc3 - en
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
AV Evasion with the Veil Framework
AV Evasion with the Veil FrameworkAV Evasion with the Veil Framework
AV Evasion with the Veil Framework
 
Final (3).pptx
Final (3).pptxFinal (3).pptx
Final (3).pptx
 
VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...
VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...
VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...
 
Clean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code CampClean Code Part II - Dependency Injection at SoCal Code Camp
Clean Code Part II - Dependency Injection at SoCal Code Camp
 
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian GötzingerMASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
 
Scalable constrained spectral clustering
Scalable constrained spectral clusteringScalable constrained spectral clustering
Scalable constrained spectral clustering
 
PVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ code
 
On technology transfer: experience from the CARP project... and beyond
On technology transfer: experience from the CARP project... and beyondOn technology transfer: experience from the CARP project... and beyond
On technology transfer: experience from the CARP project... and beyond
 
"How to create an infrastructure in .NET", Leonid Chetverikov
"How to create an infrastructure in .NET", Leonid Chetverikov"How to create an infrastructure in .NET", Leonid Chetverikov
"How to create an infrastructure in .NET", Leonid Chetverikov
 
Close encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet CodeClose encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet Code
 
Close Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet codeClose Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet code
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise Environment
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as Code
 
CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...
CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...
CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...
 

Mais de Jiří Kiml (6)

TestNG & JPA Validation
TestNG & JPA ValidationTestNG & JPA Validation
TestNG & JPA Validation
 
Jpa & hibernate
Jpa & hibernateJpa & hibernate
Jpa & hibernate
 
Test antipatterns
Test antipatternsTest antipatterns
Test antipatterns
 
Matlanek 2007 ids11
Matlanek 2007 ids11Matlanek 2007 ids11
Matlanek 2007 ids11
 
Matlanek 2007 sql_optimalizace
Matlanek 2007 sql_optimalizaceMatlanek 2007 sql_optimalizace
Matlanek 2007 sql_optimalizace
 
Tdd
TddTdd
Tdd
 

Último

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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
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
 
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, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 

Design by contract

  • 1. Design by Contract Jiří Kiml, 18/08/2011, Bern www.querity.cz
  • 2. Agenda ►Motivation ►DBC ►Support in JAVA ►Eclipse examples ►Summary ►Links www.querity.cz
  • 3. Motivation Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding ►Wouldn't it be nice if all Java classes that you use, including your own, lived up to their promises? www.querity.cz
  • 4. Design by Contract (1) ►The Design by Contract (DBC) software development technique ensures high- quality software by guaranteeing that every component of a system lives up to its expectations. As a developer using DBC, you specify component contracts as part of the component's interface. The contract specifies what that component expects of clients and what clients can expect of it. ►Bertrand Meyer developed DBC as part of his Eiffel programming language. Regardless of its origin, DBC is a valuable design technique for all programming languages, including Java. www.querity.cz
  • 5. Design by Contract (2) ►Central to DBC is the notion of an assertion ►At runtime we evaluate the assertions at specific checkpoints during the system's execution. www.querity.cz
  • 6. Kinds of Assert expressions ►Preconditions ►Postconditions ►Invariants www.querity.cz
  • 7. Preconditions ►Preconditions specify conditions that must hold before a method can execute. As such, they are evaluated just before a method executes. Preconditions involve the system state and the arguments passed into the method. ►Preconditions specify obligations that a client of a software component must meet before it may invoke a particular method of the component. ►If a precondition fails, a bug is in a software component's client. www.querity.cz
  • 8. Postconditions ►In contrast, postconditions specify conditions that must hold after a method completes. Consequently, postconditions are executed after a method completes. Postconditions involve the old system state, the new system state, the method arguments, and the method's return value. ►Postconditions specify guarantees that a software component makes to its clients. If a postcondition is violated, the software component has a bug. www.querity.cz
  • 9. Invariants ►An invariant specifies a condition that must hold any time a client could invoke an object's method. Invariants are defined as part of a class definition. In practice, invariants are evaluated any time before and after a method on any class instance executes. A violation of an invariant may indicate a bug in either the client or the software component. www.querity.cz
  • 10. Support in JAVA ►Assert keyword ►Many third party solutions (annotations, AspectJ) ►DBC class www.querity.cz
  • 11. Eclipse examples ► XXXX www.querity.cz
  • 12. Summary ►Contracts in code are good ►Easy to use ►Correctness ►Robustness www.querity.cz
  • 13. Links ►Two presentations: – http://www.eiffel.com/developers/presentations/ ►http://en.wikipedia.org/wiki/Design_by_con tract www.querity.cz
  • 14. Questions … … and maybe answers www.querity.cz
  • 15. Thank you Jiří Kiml , 18/08/2011, Bern www.querity.cz