One-to-One relation classes

Posted by SeyZ on Stack Overflow See other posts from Stack Overflow or by SeyZ
Published on 2011-01-02T16:22:50Z Indexed on 2011/01/02 16:53 UTC
Read the original article Hit count: 131

Filed under:
|

I want to have a class named ProjectDirectory and a class named MetaDirectory. Each project has a MetaDirectory which contains some meta data. Is it the good way to write the classes like this:

class ProjectDirectory(object):
    def __init__(self, directory=None):
        self.directory = directory
        self.meta_directory = MetaDirectory(self)
    def __repr__(self):
        return self.directory

class MetaDirectory(object):
    def __init__(self, project_directory=None):
        self.project_directory = project_directory
        self.directory = "%s/.meta/" % project_directory

ProjectDirectory has a reference to MetaDirectory and MetaDirectory has a reference to ProjectDirectory.

Is there an other solution or this solution is good ?

© Stack Overflow or respective owner

Related posts about python

Related posts about oop