Re: Inheritance and Interfaces

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Jay,

Talk about having a "duh" moment. That works perfectly. I REALLY don't
know why I didn't think of it.

However, at the risk of repeating the "duh" offense, I am also trying to
implement the IDataErrorInfo interface. The difference here is that the
items I'm dealing with are not methods as in the INotifyPropertyChanged
interface. IDataErrorInfo implements two properties. I'm running into
the same problem as described previously.

Do you have another bit of charity for this VERY tired amateur? ;o)

Thanks,
Glen

"Jay B. Harlow [MVP - Outlook]" wrote:
>Glen,
>You only need to implement INotifyPropertyChanged in the base class,
then
>allow derived classes to raise the event. The "standard" pattern is to
do
>something like:
>
>Public Class Person
> Implements System.ComponentModel.INotifyPropertyChanged
>
> Public Event PropertyChanged(ByVal sender As Object, ByVal e As
>System.ComponentModel.PropertyChangedEventArgs) Implements
>System.ComponentModel.INotifyPropertyChanged.PropertyChanged
>
> Protected Overridable Sub OnPropertyChanged(ByVal e As
>System.ComponentModel.PropertyChangedEventArgs)
> RaiseEvent PropertyChanged(Me, e)
> End Sub
>
> Private m_name As String
>
> Public Property Name() As String
> Get
> Return m_name
> End Get
> Set(ByVal value As String)
> m_name = value
> Dim e As New
>System.ComponentModel.PropertyChangedEventArgs("Name")
> OnPropertyChanged(e)
> End Set
> End Property
>
>End Class
>
>Public Class Employee
> Inherits Person
>
> Private m_salary As String
>
> Public Property Salary() As String
> Get
> Return m_salary
> End Get
> Set(ByVal value As String)
> m_salary = value
> Dim e As New
>System.ComponentModel.PropertyChangedEventArgs("Salary")
> OnPropertyChanged(e)
> End Set
> End Property
>
>End Class
>
>The Overridable Sub OnPropertyChanged allows derived classes to raise
the
>event, alternatively derived class can override the method & offer
extra
>processing when the event is raised...
>
>For details on the above pattern see:
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenr
ef/html/cpconEventNamingGuidelines.asp
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenr
ef/html/cpconEventUsageGuidelines.asp
>
>--
>Hope this helps
>Jay [MVP - Outlook]
>..NET Application Architect, Enthusiast, & Evangelist
>T.S. Bradley - http://www.tsbradley.net
>
>
><gwolinsky@xxxxxxxxxxxxxxxx> wrote in message
>news:1131129278.358400.48630@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>|I originally posted this in the WindowsForms group but that may not
>| have been the best place to post it. So, I am reposting here.
>|
>| --------------------------------------
>|
>| I am trying to implement the new INotifyPropertyChanged interface in
my
>| custom business object. The problem I'm having is with the
inheritance
>| model.
>|
>| I have a base object called "Person". The object "Employee" inherits
>| from person and provides additional properties and methods.
>|
>| I implemented INotifyPropertyChanged in the Person base class and
>| everything worked great. However, how do I implement it in the
derived
>| "Employee" class.
>|
>| If I implement it the same way, the compiler warns that:
>|
>| "event 'PropertyChanged' conflicts with event 'PropertyChanged' in
the
>| base class 'Person' and should be declared 'Shadows'."
>|
>| OK. So I change the event definition to "Shadows". Then, I still
get
>| the following warning:
>|
>| "'System.ComponentModel.INotifyPropertyChanged.PropertyChanged' is
>| already implemented by the base class 'Common.Person'.
>| Re-implementation of event assumed."
>|
>| If I ignore BOTH warnings and run it, it works fine. If I designate
>| the event as "Shadows" and run it, it works fine.
>|
>| Am I doing this correctly or am I in high weeds?
>|
>| Any help would be greatly appreciated.
>|
>| Sincerely,
>| Glen Wolinsky
>|
>
>



--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
.



Relevant Pages

  • Re: Inheritance question
    ... I do define the string in each of the derived classes as well as the base. ... defined in the base class, as you suggested, which works perfectly. ... impression that I was putting the keywords in the base class. ...
    (microsoft.public.dotnet.framework)
  • Re: a sharde member variable in base class
    ... > Is this variable shared among all of the instances of the base class ... > and derived classes? ... > Shared Function GetId() as String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Not pure virtual functions and mixing virtual and non virtual methods
    ... Should I call base class implementation or not? ... But doing the above assumes that one answer is good for all, that all derived classes will want the base class method called in the same way. ... More generally, the way I see it, if you combine invariant implementation with variant parts, you have no elegant way to change the variant part. ... Following them will remove all inheritance relationships. ...
    (comp.object)
  • Re: Shadows and Overrides and Bears, Oh My!
    ... I have one method in the base class that all derived classes need to be able ... I also want to have other methods named Populate that have different ... DoMyPopulatin(MyObject as BaseObject, a as String) ... Public Shadows Sub Populate ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Shadows and Overrides and Bears, Oh My!
    ... I have one method in the base class that all derived classes need to be able ... I also want to have other methods named Populate that have different ... DoMyPopulatin(MyObject as BaseObject, a as String) ... Public Shadows Sub Populate ...
    (microsoft.public.dotnet.general)