Giter VIP home page Giter VIP logo

Comments (1)

BenRomberg avatar BenRomberg commented on July 20, 2024

"Temporary breaking of class invariance between private method calls is possible, although not encouraged."

This has been fixed.

The other issue with class-invariants being checked during construction of an object can thus only happen after a publicly available method (meaning public, protected or package-private in Java) is being called during construction of an object. As they could also be called during any other moment during the lifecycle of the object, they must be able to assume that the class-invariant holds before being called themselves. With this assumption in mind, it should not be an issue to call the class-invariant after a publicly available method during construction of an object.

Also, the example on c2.com is using another assumption: That the assertValid() method is being overridden in the subclass. The call order will differ between the example and the C4J implementation as follows:

c2.com Example:
Derived();
Base();
{ body of Base() }
Derived.assertValid(); // <-- problem: Invariant called before body of Derived() is being evaluated
Base.assertValid();
{ body of Derived() }
Derived.assertValid();
Base.assertValid();

C4J equivalent:
Derived();
Base();
{ body of Base() }
Base.classInvariant();
{ body of Derived() }
Base.classInvariant();
Derive.classInvariant();

This also shows why doing Contracts in Java without using a framework is quite complicated.

from c4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.