Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Design issues
Message
De
05/08/2010 14:25:37
 
 
À
05/08/2010 14:01:23
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Titre:
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01475236
Message ID:
01475387
Vues:
37
>>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()
>
>I think this approach is similar to the one from Denis. Also, later on in this thread, in Message #1475334, I provided the current approach I am using which is simply about making a public method in the client and calling it from the class. Do you see any downsize in that approach?

Hi,
Guess I hadn't read all of the thread when I replied :-}

Yes, Dennis's approach is essentially the same as mine - but I haven't used VB enough to know whether this is as simple as a straightforward delegate.

The only problem I see with your approach is that the type of loParser.oOriginator must implement the ParseGetContent() method which introduces a restriction (but it's not clear from the code snippet you show why this is even accepted by the compiler). If you use a delegate then the Parser could be used from any type.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform