Skip to content
This repository has been archived by the owner on Oct 24, 2019. It is now read-only.
/ specification.dart Public archive

Dart implementation of the Specification pattern in Domain Driven Design.

License

Notifications You must be signed in to change notification settings

thara/specification.dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Specification.dart

Build Status

Implementation of the Specification pattern in Domain Driven Design by Dart.

What is the specificaiton pattern?

the specification pattern is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using boolean logic.

"Specification pattern." Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc. 15 April 2013. Web. 27 April 2013.

Examples

import 'package:specification/specification.dart' as spec;

main () {
  var spec1 = spec.expr((value) => value.length > 2);
  var spec2 = spec.expr((String str) => str.startsWith("abc"));
  
  var conjunction = spec1 & spec2;
  print(conjunction.isSatisfiedBy("a"));      // false
  print(conjunction.isSatisfiedBy("abb"));    // false
  print(conjunction.isSatisfiedBy("abcde"));  // true
  
  var disjuction = spec1 | spec2;
  print(disjuction.isSatisfiedBy("a"));       // false
  print(disjuction.isSatisfiedBy("abb"));     // true
  print(disjuction.isSatisfiedBy("abcde"));   // true
  
  var negation = ~spec1;
  print(negation.isSatisfiedBy("a"));         // true
  print(negation.isSatisfiedBy("abb"));       // false
  print(negation.isSatisfiedBy("abcde""));     // false
  
  var exclusiveDisjunction = spec1 ^ spec2;
  print(exclusiveDisjunction.isSatisfiedBy("a"));     // false
  print(exclusiveDisjunction.isSatisfiedBy("abb"));   // true
  print(exclusiveDisjunction.isSatisfiedBy("abcde")); // false
}

Licence

see LICENSE

Author

About

Dart implementation of the Specification pattern in Domain Driven Design.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages