Re: Inheritance and Interfaces
- From: Glen Wolinsky <gwolinsky@xxxxxxxxxxxxxxxx>
- Date: Fri, 04 Nov 2005 13:45:31 -0800
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
.
- Follow-Ups:
- Re: Inheritance and Interfaces
- From: Jay B. Harlow [MVP - Outlook]
- Re: Inheritance and Interfaces
- Prev by Date: Re: CreateFile API call in VB .NET
- Next by Date: Re: is debugging on VS2005 ever slow sheesh...
- Previous by thread: Inheritance and Interfaces
- Next by thread: Re: Inheritance and Interfaces
- Index(es):
Relevant Pages
|