[Issue 3194] invariant should be checked at the beginning and end of protected functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 22 11:57:29 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=3194


Diego Canuhe <canuhedc at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |canuhedc at gmail.com


--- Comment #2 from Diego Canuhe <canuhedc at gmail.com> 2011-06-22 11:52:38 PDT ---
(In reply to comment #1)
> Patch for D2
> https://github.com/D-Programming-Language/dmd/pull/112

I disagree.
Even while you can easily access protected methods of a class, they are
intended for internal use, otherwise they'd be public.

Consider:

class A
{
    abstract protected SomeType[] getData();

    public void processData()
    {
        //do something that breaks the invariants
        foreach (SomeType element; getData())
        {
            //do something...
        }
        //do something that restores the invariants
    }

    invariant() {...}
}

a class B derived from A implementing getData() shouldn't have to respect the
invariants while entering/leaving getData(). Anything regarding getData()'s
side-effects should be put in an out clause.

BTW, abstract functions shouldn't require a body clause accompanying in and out
clauses

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list