Two variants of class hierachy

Victor Porton porton at narod.ru
Sat Nov 19 13:00:41 EST 2016


Peter Otten wrote:

> Victor Porton wrote:
> 
>> I am developing software which shows hierarchical information (tree),
>> including issues and comments from BitBucket (comments are sub-nodes of
>> issues, thus it forms a tree).
>> 
>> There are two kinds of objects in the hierarchy: a. with a (possibly
>> long) paginated list of childs; b. with a short list of strings, each
>> string being associated with a child object.
>> 
>> I have two variants of class inheritance in mind. Please help to decide
>> which is better.
>> 
>> The first one declares only one base class, but some its method remain
>> unimplemented (raise NotImplementedError) even in derived classes.
> 
> Two observations:
> 
> In Python you can also use "duck-typing" -- if you don't want to share
> code between the classes there is no need for an inhertitance tree at all.

I know, but explicit inheritance serves as a kind of documentation for 
readers of my code.

> Pagination is a matter of display and will be handled differently in a PDF
> document or web page, say. I would not make it part of the data structure.

Not in my case, because the data I receive is already paginated. I am not 
going to "re-paginate" it in another way.

-- 
Victor Porton - http://portonvictor.org



More information about the Python-list mailing list