- Entity attribute declaration for arbitrary types.
- Natural type hierarchy declaration (using all Scala's features).
- Complete separation of data and schema. The data can be stored in a flat List[Any] or Array and then checked and converted to a strict typed construction.
- Typed representation of instances.
Let's have a few types (that can include type aliases, traits, classes, object.types, etc.):
abstract class Shape trait BoundingRectangle final class Rectangle extends Shape with BoundingRectangle final class Circle extends Shape with BoundingRectangle
We can bind properties to any type:
object BoundingRectangleS extends PropertySeq[BoundingRectangle] { val width = simpleProperty[Int]("width") val height = simpleProperty[Int]("height") } import BoundingRectangleS._ object CircleS extends PropertySeq[Circle] { importProperties(BoundingRectangleS.toSchema) val radius = Rel[Circle, Int]("radius") } import CircleS._
Properties bound to parent types can be used freely for descendent types.
In the above example we have collected properties within a PropertySeq descendent. This allows us to immediately have full schema of corresponding type (CircleS.toSchema). Also we can declare a property outside of the schema-object:
val name = Rel[Shape, String]("name")
It is possible to have different schemas bound to the same type depending on the application requirements.
val onlyBoundingRectSchema = BoundingRectangleS.toSchema val someInfoAboutACircle = record[Circle](radius) val fullInfoAboutACircle = someInfoAboutACircle ++ onlyBoundingRectSchema
Data instances (records, frame instances) can be constructed using builder:
val circ10 = new Builder(someInfoAboutACircle). set(radius, simple(10)). toInstance val shape10 = new Builder(fullInfoAboutACircle). fillFromInstance(circ10). set(width, simple(10)). set(height, simple(10)). toInstance assert(shape10.get(radius) === circ10.get(radius))
At runtime one can make sure that some instances meets a schema:
assert(isMatching(shape10, someInfoAboutACircle)) assert(isMatching(shape10, fullInfoAboutACircle)) assert(isMatching(circ10 , someInfoAboutACircle)) assert(nonMatching(circ10 , fullInfoAboutACircle))
The current version of the library is "ru.primetalk:synapse-frames_2.10:1.3.3".