Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class based contracts #211

Open
4 tasks
mlhaufe opened this issue May 9, 2021 · 2 comments
Open
4 tasks

Class based contracts #211

mlhaufe opened this issue May 9, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request feature/contract The Contract declaration feature/contracts-constructor The top level constructor
Milestone

Comments

@mlhaufe
Copy link
Contributor

mlhaufe commented May 9, 2021

Currently contracts are defined as such:

const baseContract = new Contract<Base>({
    [invariant]: self => ...,
    featureName: {
        demands(self, args) { ... },
        ensures(self, old, args) { ... }
    }
}),
subContract = new Contract<Sub>({
    [extend]: baseContract,
    [invariant]: self => ...,
    featureName: {
        rescue(self, error, args, retry) { ...; retry(); }
    }
});

@Contracted(baseContract)
class Base { ... }

@Contracted(subContract)
class Sub extends Base { ... }

The extend property is a reinvention of the native class functionality, except currently the contract property is not doing the equivalent checks. Contracts should be changed to utilize the native class functionality:

class BaseContract extends Contract<Base> {
    [invariant](ctx) { ... }
    featureName() {
        return {
            demands(ctx, args) { ... },
            ensures(ctx, old, returnValue, args) {  ... }
        }
    }
}

class SubContract extends BaseContract<Sub> {
    [invariant](){ return this.ctx.value <= 100 }
    featureName() {
        return {
            rescue(ctx, error, args, retry){ ...; retry(...args); }
        }
    }
}

@Contracted(BaseContract)
class Base {...}

@Contracted(SubContract)
class Sub extends Base { ... }
  • Update implementation
  • Update README
  • Update Unit tests
  • Update Changelog
@mlhaufe mlhaufe added the feature/contract The Contract declaration label May 9, 2021
@mlhaufe mlhaufe added this to the v0.21.0 milestone May 9, 2021
@mlhaufe mlhaufe self-assigned this May 9, 2021
@mlhaufe
Copy link
Contributor Author

mlhaufe commented May 9, 2021

Does [checkedMode] become an argument of the constructor?

Presently all contract usages are (en|dis)abled, as a constructor argument it would enable the instance of the contract to be (en|dis)abled

@mlhaufe mlhaufe modified the milestones: v0.21.0, v0.22.0 May 14, 2021
@mlhaufe mlhaufe added feature/contracts-constructor The top level constructor enhancement New feature or request labels Nov 21, 2021
@mlhaufe
Copy link
Contributor Author

mlhaufe commented Nov 21, 2021

  1. How could @override be used here in the class form?
  2. Could Feature Oriented Programming be leveraged to simplify the implementation?

@mlhaufe mlhaufe modified the milestones: v0.22.0, v0.23.0 Nov 21, 2021
@mlhaufe mlhaufe modified the milestones: v0.23.0, v0.24.0 Jan 29, 2022
@mlhaufe mlhaufe modified the milestones: v0.24.0, v0.25.0 Aug 21, 2022
@mlhaufe mlhaufe modified the milestones: v0.25.0, v0.26.0 Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature/contract The Contract declaration feature/contracts-constructor The top level constructor
Projects
None yet
Development

No branches or pull requests

1 participant