Re: [StGIT PATCH 3/5] Create a git.Branch class as ancestor of stack.Stack
- From
- Catalin Marinas <catalin.marinas@gmail.com>
- Date
- Jun 5, 2008, 12:03 UTC
- Message-ID
- <b0943d9e0806050503x40191104ye332d6a8435811a5@mail.gmail.com>
- In-Reply-To
- <20080605070126.GC23209@diana.vm.bytemark.co.uk>
2008/6/5 Karl Hasselström <kha@treskal.com>:
Show 7 quoted lines
> On 2008-06-04 22:13:35 +0100, Catalin Marinas wrote: >> + def __init__(self, repository, name): >> + self._repository = repository >> + self._name = name > > Using double leading underscores will give you a class-local name. Why > just one?
Just a convention: double underscore - private, simple underscore - protected (using C++ or Java naming). The _repository or _name are meant to be made available to a derived class (stack.Stack in our case), though we have the corresponding public properties already.
Show 7 quoted lines
>> + @classmethod >> + def create(cls, repository, name, create_at = None): > > Minor nit: in case of things that are clearly "owned" by other things > (git objects are owned by a git repository, for example), I've tried > to put the creation function in the owner, not the owned. I'm not > insisting, though.
As I see these things, the git.Repository and the derived stack.Repository are indeed object factories but they are mainly responsible for creating/returning a new Python object and passing some arguments to the class' __init__. The Repository object doesn't need to know more than the name as the rest is handled by __init__.
The same goes for the "create" function, the repository shouldn't need to know the directory or files structure that a Stack or Branch are using. I think we get a clearer separation this way.
-- Catalin