[Zope-dev] RFC: RelationAware class for relations
betweenobjects
Roché Compaan
roche@upfrontsystems.co.za
Wed, 30 Apr 2003 12:31:20 +0200
On Tue, 29 Apr 2003 14:28:10 -0400
Shane Hathaway <shane@zope.com> wrote:
> Leonardo Rochael Almeida wrote:
> > In Zope and in Python we already have RELATIONs, by putting a bunch of
> > similar objects in a list or as children of a Folder or ObjectManager.
> > We still don't have a convenient way to express RELATIONSHIPs, and this
> > thread looks very promising in this regard, but the APIs being discussed
> > here are already calling RELATIONSHIPs RELATIONs and this worries me a
> > little.
>
> I like that distinction. We should stick to it.
>
> To clarify, the API used by the example I posted formalizes relations
> with the intent of making relationships easy to create and discover. A
> goal that's important to me is the ability to infer new relationships
> from an existing data set, which is relatively easy to do with formal
> relations. Here is the example with some revisions to demonstrate more
> of what I have in mind:
>
>
> class IRegistration (Interface):
> student = Attribute('student', 'A Student object')
> course = Attribute('course', 'A Course object')
> term = Attribute('term', 'A Term object')
>
> registrations = RelationBuilder(IRegistration)
> current_registrations = registrations.view(filter=CurrentTermFilter())
>
> class Registration (Persistent):
> implements(IRegistration)
> def __init__(self, student, course, term):
> self.student = student
> self.course = course
> self.term = term
>
> class Term (Persistent):
> def __init__(self, name):
> self.name = name
>
> class Student (Persistent):
> current_courses = current_registrations.view(
> match='student', select='course')
> all_courses = registrations.view(
> match='student', select='course')
>
> class Course (Persistent):
> current_students = current_registrations.view(
> match='course', select='student')
> all_students = registrations.view(
> match='course', select='student')
>
>
> *shrug* I know how to implement this, but I don't know if it's a good
> idea. Thoughts?
Just to help me understand I am going to first say what I see here.
In this API, relations are defined outside classes (registrations)
whereas the relationships are defined in the class
(Course.current_students, etc).
Jeremy's API does not formalise relations, it only provides methods to
build relationships between objects. Ok, I think I understand the difference
between relations and relationships now ;-)
When one formalises a relation ie. that of 'registrations' it does not
require any defined classes. This is big plus in my mind because:
- relations are described in a way that does not require knowledge
of any classes or how classes will use them to build relationships.
- many *relationships* (current_courses, all_courses) can be
specified on a single class in the form of static attributes using
different views of a single *relation* (registrations).
- one class can have a relationship with another class without the
other class knowing about it. This is usefull if you want to
relate to classes that are not under you control.
Shane, show us more :-) You've *defined* certain relationships but have
not shown how to *create* them and how to use them. Will this be
possible:
me = Student()
zope101 = Course("Introduction to Zope")
zope101.current_students.add(me)
assert me.current_courses.zope101.name == "Introduction to Zope"
I think we should make a list of requirements and use cases - at the
moment it seems as if we are all pointing at a mountain but not the same
one. It is difficult to evaluate API's if we don't have requirements.
I'll try to come up with a list this afternoon.
--
Roché Compaan
Upfront Systems http://www.upfrontsystems.co.za