[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [IMP-users] A remark concerning software design and the get_leaves() function

Late response.

The motivation is the "principle of least privilege". Basically, since the get_leaves() method doesn't need to do anything other than call a bunch of public methods on Hierarchy (eg get_children() until we reach the leaves), it doesn't need to be a member. And since it doesn't need to be a member, we don't make it one. The benefit is that doing this reduces the amount of code that is tied to the implementation of the Hierarchy class (that is, if we change how Hierarchy is implemented internally, we know we don't have to change get_leaves()).

The other advantage is that people who don't have access to Hierarchy code can add methods that act similarly (eg, get_leaves() and get_my_special_nodes() are both used the same way).

But yes, it does add a bit more to remember over having everything being a member method, and so isn't strictly better than having it as a method.

On Jul 22, 2010, at 8:01 AM, Benjamin SCHWARZ wrote:

> It is probably a question of taste, but every time I need the leaves of a hierarchy, my intuitive guess is to write mh.get_leaves() instead of IMP.core.get_leaves(mh). So I wonder if there are gory reasons for this function to be outside the class…
>  --Ben
> _______________________________________________
> IMP-users mailing list
> https://salilab.org/mailman/listinfo/imp-users