Giter VIP home page Giter VIP logo

xref's Introduction

XRef

License Project status JitPack Build Status Code coverage Code quality

XRef is a kotlin library allowing management of cross references via kotlin property delegation

Project status

This project is discontinued. It will be no longer maintained and no support will be provided.

The reason, is that it is less usefull as expected in practice. Usually good design would tend to create immuatable data structures and service to use them. So the need of auto-managed relation is almost inexistant.

Anyone is free to read, study, modify and to create derivated products.

Use

KDoc is published here: https://jcornaz.github.io/xref/doc/1.0/xref/xref/index.html

Declare a relation

Here is an example of a parent-child relation (which is one-to-many)

// Define the relation. References will be managed here.
object ParentChildRelation : OneToMany<Parent, Child>()

// Declare the parent class
class Parent {

    // Delegate the children property to the relation management
    var children: Set<Child> by ParentChildRelation.right()
}

// Declare the child class
class Child {

    // Delegate the parent property to the relation management
    var parent: Parent? by ParentChildRelation.left()
}

And that's it ! Now you can assign a parent to a child, or add children to a parent. It will always be kept coherent by XRef.

Use the relation

Once you have the relation defined, you can use it as you would with standard properties.

// given
val parent = Parent()
val children = setOf(Child(), Child())

// when
parent.children = children

// then
parent.children shouldBe children
children.forEach { it.parent shouldBe parent }

Supported relations

Currently XRef support 4 types of relations :

  • ManyToMany
  • OneToOne
  • OneToMany
  • NotNullOneToMany (in a parent-child scenario, it would means that the child has always a parent)

Motivation

Even if it is always simpler to use immutable instances and not cross reference objects. Sometime, we have to create mutable classes that can be cross referenced. In these cases, writing code that always keep a coherent state in your references can quickly generate boilerplate code, and demand to invest unnecessary time to make sure it is well tested and reliable.

The goal of this project is to centralize the reference management code and provide kotlin delegation properties for that. Then there cross referencing don't generate more boilerplate code, become reliable AND quick and easy to write.

Add XRef to your project

Get the artifacts from jitpack

With gradle

repositories {
    jcenter()
    maven { url 'https://jitpack.io' }
}

dependencies {
    compile 'com.github.jcornaz:xref:v1.0-RC1'
}

With maven, sbt or leiningen

Follow theses instructions

xref's People

Contributors

jcornaz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.