How to group similar member functions from different classes?
kinke via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 18 11:25:52 PDT 2016
On Saturday, 18 June 2016 at 07:03:25 UTC, cy wrote:
> So how would you do it? Defining A.foo, B.foo, etc in one
> place, and A.bar, B.bar, etc in another?
No such thing in D. But you can always be creative and use an
overloaded helper function containing the actual implementation
if you want to group the code by functionality and not by type:
class A { int foo() { return doFoo(this); }
class B : A { int foo() { return doFoo(this); }
...
void doFoo(A a) { ... }
void doFoo(B b) { ... }
If you need full access to the members, the helpers would need to
be in the same module, otherwise you can put them into a separate
helper.
More information about the Digitalmars-d-learn
mailing list