Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Design issues
Message
From
05/08/2010 13:51:50
 
 
To
04/08/2010 22:19:50
General information
Forum:
ASP.NET
Category:
Class design
Title:
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01475236
Message ID:
01475378
Views:
49
>Usually, when I want to define a method overridable in a class, I do it like this:
>
>
>    Public Class Parser
>
>        Public Overridable Function ReplaceWithThisContent() As Boolean
>            Return True
>        End Function
>
>    End Class
>
>
>So, basically, in the client, I can define this overridable method like this:
>
>
>        Public Overrides Function ReplaceWithThisContent() As Boolean
>            Return True
>        End Function
>
>
>This works for a long as the client is inheriting from the class.
>
>However, in one particular class, which is already inheriting from something else, I need to create an object from Parser class. This works. So, in the client, I may have something like this:
>
>
>Public Class ViewPagePage
>
>    Inherits Framework.Framework.ViewPage
>
>    Public Overrides Function GetPage() As Boolean
>        Dim loParser As Framework.Framework.Parser = New Framework.Framework.Parser(oProcess)
>
>        ' Parse for table
>        loParser.cTable = "Company"
>        loParser.cContent = lcNotes
>        loParser.oOriginator = Me
>        If Not loParser.ParseForTable() Then
>            Return False
>        End If
>
>        Return True
>    End Function
>
>
>However, because the client is not inheriting from the Parser class, I cannot benefit from its Overridable ReplaceWithThisContent() method.
>
>Because, in the Parser.ParseForTable() method, I need to call a method in the client for every record of a loop which is being processed at the class level. So, basically, the class handles all the logistic but for every record it processes, some sub logic is custom to each client. This works ok on all other places I have something like this because the client is always inheriting from the class itself. But, in this case, the client is already inheriting from another class. So, I am losing the capability of using the overridable method. Any idea?

I think you need to use a delegate. Oversimplifing your example (and using C# I'm afraid):
   public class ViewPageClass
    {
        public void GetPage()
        {
            Parser p = new Parser();
           // Replace default handling.
            p.handler = SpecificReplaceWithThisContent;
            bool b = p.ReplaceWithThisContent();
        }

        public bool SpecificReplaceWithThisContent()
        {
            return false;
        }

    }
    public class Parser
    {
        public delegate bool Doit();

        public Doit handler;

        public bool ReplaceWithThisContent()
        {
            if (handler != null)
            {
                return handler();
            }
            else
            {
                //Do the default handling. E.g:
                return false;
            }
        }
    }}
So a call to Parser.ReplaceWithThisContent() will actually run the ViewPageClass.SpecificReplaceWithContent()
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform