Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AngelScript OO Capabilities - Inheritance
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#7
RE: AngelScript OO Capabilities - Inheritance

I found a way to do it. Essentially, an object composition based approach. In a way, it's a reduced Bridge pattern.
  • You create two classes: Base and BaseImpl - the implementation class. BaseImpl should only define the implementations of the methods that are to be called from the derived class.
  • You than make a BaseImpl object be a member variable (a.k.a. member field) of Base, and forward all calls to the private methods to their corresponding implementations, via the BaseImpl instance.
  • Finally, since Derived can access private member variables of Base, you simply call the appropriate methods from the subclass.
Essentially:
+---------+                   +----------+
|  Base   |------------------>| BaseImpl |
+---------+                   +----------+
  /|\
   |
   |
<<derives from>>
   |
+---------+
| Derived |
+---------+

Or in code:
PHP Code: (Select All)
class Base
{
    private 
BaseImplimpl;

    
Base()
    {
        @
impl BaseImpl();
    }

    
void DoSomething()
    {
        
// blah, blah...
    
        
OnDoSomething();
    
        
// blah...
    
}
    
    private 
void OnDoSomething()    // the method to be overridden
    
{
        
impl.OnDoSomething();
    }
}

class 
BaseImpl
{
    
void OnDoSomething()
    {
        
/* the implementation */
    
}
}

class 
Derived Base
{
    private 
void OnDoSomething()    // the override
    
{
        
/* <the new implementation> 
         *     blah, blah, blah...
         * </the new implementation> */

        
impl.OnDoSomething();   // calls the base class implementation
    
}

(This post was last modified: 08-17-2012, 12:37 AM by TheGreatCthulhu.)
08-17-2012, 12:31 AM
Find


Messages In This Thread
RE: AngelScript OO Capabilities - Inheritance - by TheGreatCthulhu - 08-17-2012, 12:31 AM



Users browsing this thread: 1 Guest(s)