ACV Inheritance
People who can't figure out <em>class inheritance</em> (java/C++) or <em>prototypal inheritance</em> (javascript) use the <b>ACV</b> inheritance pattern. More accurately the ^A^C^V pattern.
Here's how it works:
- You find a class you like, and want to extend.
- You hold down the "Control" button on your keyboard.
- While doing so, you press 'A' key, then release, then press the 'C' key, and release.
- Now you open a new text file.
- Name the file according to the new class you're making
- In the new (empty) text file you again press down the "Control" key
- Now you press the 'V' key.
Hey presto! You now have a "derived class". You can "override" some, or all of the methods, or properties - public AND private!
It seems to be a very common pattern amongst embedded developers, not sure why.
POWER USER TIP: If you want to override a method in the base class, but want to still call it from your derived class. Simply type 'parent' directly in front of the method name. Here's an example:
/** BEFORE OVERRIDE **/
int Foo(char *x){
int y;
// do work
// ...
return y;
}
/** WITH OVERRIDE **/
int parentFoo(char *x){
int y;
// do work
// ...
return y;
}
int Foo(char *x){
// modify x
// ...
return parentFoo(x);
}
0 Comments:
Post a Comment
<< Home