473,809 Members | 2,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheritance and Interfaces

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 INotifyProperty Changed 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 INotifyProperty Changed 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 'PropertyChange d' conflicts with event 'PropertyChange d' 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.Compon entModel.INotif yPropertyChange d.PropertyChang ed' 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

Nov 23 '05
15 1640
Glen,
| So, in order to be consistent, are you saying I should initialize the
| "properties " (not the backing variables) in a subroutine that is called
| by both the constructor AND the "Get" routine?
Yes.
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Glen Wolinsky" <gw*******@mill ermartin.com> wrote in message
news:uV******** ********@TK2MSF TNGP10.phx.gbl. ..
| Jay,
|
| There are two ways my objects are initialized:
|
| 1. If this is a "get" operation, the object loads the employee data from
| the database and sets all the backing fields;
|
| 2. This is a new employee and the backing fields are initialized during
| variable instantiation.
|
| Option 2 should be full of errors since it's empty and there are several
| required fields. Option 1 would have to use the properties instead of
| the backing fields like you mentioned in order make sure the current
| data is valid.
|
| So, in order to be consistent, are you saying I should initialize the
| "properties " (not the backing variables) in a subroutine that is called
| by both the constructor AND the "Get" routine?
|
| Thanks,
| Glen
|
| --
| Sent via .NET Newsgroups
| http://www.dotnetnewsgroups.com
Nov 23 '05 #11
Jay,

You have been a tremendous help. Thank you and God bless.

Sincerely,
Glen Wolinsky

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 23 '05 #12
Jay,

Just when you thought it was safe to back into the forum.....I'm back.
;o)

I am implementing the solution we discussed. Everything seemed to be
working fine except for one issue.

My boss did not like the fact that on a NEW employee, the data entry
screen came up not only blank (as it should be) but with ALL the error
indicators already on (because I run the Employee.Valida te routine
during construction that validates everything in the object). What he
wanted was that when the entry screen initially appears, there are no
validation errors. Then as the user attempts data entry, the validation
happens on a per-field basis. If the programmer attempts to run the ADD
or UPDATE routines in the Employee object, the object runs that full
validation routine and if it's NOT valid throws an exception.

I thought, "Ok, I'll just NOT run the full validation when the employee
object is constructed. Then, the individual property set routines will
validate on each one." Well, the problem is that when the user is
tabbing through blank fields (which shouldn't be blank) the values
aren't changing so the validation routines aren't running and the
errorproviders aren't showing.

Now for even stranger things. I put a test button on the form. This
button does nothing but run the employee object's full validate routine
(mentioned above) which just runs the validation routines on ALL the
properties. I thought this would make all the validators show up, but
they don't!!

Now, after trying that full validation, I change any field on the form
so that the validation fires, ALL the OTHER validations suddenly
appear!!!

I also found that when I use that test button to try and validate
EVERYTHING, if -- in the employee object -- I run the OnChangedProper ty
event for each property after the property is validated, the
errorproviders show up.

Does any of this make sense? If so, do you have any more tricks in your
bag?

As before, your help would be grealy appreciated.

Sincerely,
Glen
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 23 '05 #13
<gw*******@mill ermartin.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
I implemented INotifyProperty Changed in the Person base class and
everything worked great. However, how do I implement it in the
derived "Employee" class.


This may be too little, too late, but I'll pitch in anyway in the hope
that, if I've been doing it completely wrong[ly?], someone will set
me straight.

I implement the Interface in the Base class, but make the
"implementi ng" routine Overridable. Each subclass can then supply
its own implementation that gets used instead of that in the Base class.

Class base
Implements ISomeInterface
Private Overridable Sub s1() _
Implements ISomeInterface. s1
. . .
End Class

Class derived
Inherits base
Private Overrides Sub s1()
. . .
End Class

Comments/Suggestions/derisory laughter, anyone?

Regards,
Phill W.
Nov 23 '05 #14
Phill,

In my numerous mutations of the code I was working with, I tried exactly
what you described. At least in regards to the IDataErrorInfo
interface, the behind-the-scenes wiring didn't work properly in the
subclasses or class-properties. Of course, it's entirely possible that
there was something else wrong with the code I tried.

My .02

Sincerely,
Glen
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 23 '05 #15
Jay,
| Does any of this make sense? If so, do you have any more tricks in your
| bag?
Yes it makes sense, unfortunately I have not yet had time to look at it to
offer any sound advice.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Glen Wolinsky" <gw*******@mill ermartin.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
| Jay,
|
| Just when you thought it was safe to back into the forum.....I'm back.
| ;o)
|
| I am implementing the solution we discussed. Everything seemed to be
| working fine except for one issue.
|
| My boss did not like the fact that on a NEW employee, the data entry
| screen came up not only blank (as it should be) but with ALL the error
| indicators already on (because I run the Employee.Valida te routine
| during construction that validates everything in the object). What he
| wanted was that when the entry screen initially appears, there are no
| validation errors. Then as the user attempts data entry, the validation
| happens on a per-field basis. If the programmer attempts to run the ADD
| or UPDATE routines in the Employee object, the object runs that full
| validation routine and if it's NOT valid throws an exception.
|
| I thought, "Ok, I'll just NOT run the full validation when the employee
| object is constructed. Then, the individual property set routines will
| validate on each one." Well, the problem is that when the user is
| tabbing through blank fields (which shouldn't be blank) the values
| aren't changing so the validation routines aren't running and the
| errorproviders aren't showing.
|
| Now for even stranger things. I put a test button on the form. This
| button does nothing but run the employee object's full validate routine
| (mentioned above) which just runs the validation routines on ALL the
| properties. I thought this would make all the validators show up, but
| they don't!!
|
| Now, after trying that full validation, I change any field on the form
| so that the validation fires, ALL the OTHER validations suddenly
| appear!!!
|
| I also found that when I use that test button to try and validate
| EVERYTHING, if -- in the employee object -- I run the OnChangedProper ty
| event for each property after the property is validated, the
| errorproviders show up.
|
| Does any of this make sense? If so, do you have any more tricks in your
| bag?
|
| As before, your help would be grealy appreciated.
|
| Sincerely,
| Glen
|
|
| --
| Sent via .NET Newsgroups
| http://www.dotnetnewsgroups.com
Nov 23 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8396
by: Joe Delphi | last post by:
Does Visual Basic support multiple inheritance? That is one child class inheriting from more than one parent class. JD
8
3222
by: Shawn Casey | last post by:
Consider the following code: interface IBase { virtual void BaseFunction() = 0; }; interface IDerived : public IBase { virtual void DerivedFunction() = 0;
12
7061
by: Steve Jorgensen | last post by:
The classing Visual Basic and VBA support for polymorphism, let's face it, is a bit on the weak side, and built-in support for inheritance is non-existent. This little essay is about some patterns I've ended up using successfully for certain kinds of inheritance and polymorphism, and some that have not worked out so well. Let's start with obvious things that turn out not to work well: 1. Use interface classes and "Implements" for...
22
23391
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
15
7208
by: Sinex | last post by:
Hi, Why does C# disallow multiple inheritance? Whats the reason behind this? Is there any advantage or is it just a method to avoid some problems (if so, what problems?) that come with multiple inheritance? regards, Sinex
7
12880
by: Hazz | last post by:
Are there any good references/articles/books which provide clarity toward my insecurity still on deciding how to model a complex system? I still feel uncomfortable with my understanding, even though I have worked with these systems on when to decide to use interfaces (and how they should be developed) as opposed to or complemented by the use of inheritance from base classes. If I am thinking from the point of view of some specific activity...
0
1197
by: Terry Hancock | last post by:
I've been discussing PyProtocols with a a friend collaborating with me on a SF game project, about the benefits and design concept of "component architecture", and I'm a little confused by what I'm learning. I learned the concepts of "component architecture" from the Zope project, where if I'm not mistaken, "components" are essentially python "mix-in" classes, and you make a class from components by using multiple inheritance and...
23
4618
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
18
1694
by: GD | last post by:
Please remove ability to multiple inheritance in Python 3000. Multiple inheritance is bad for design, rarely used and contains many problems for usual users. Every program can be designed only with single inheritance. I also published this request at http://bugs.python.org/issue2667
3
4847
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately, due to a couple limitations of the language, MI is still not attainable (at least not succinctly). 1 - Interfaces cannot define data (only properties) 2 - Extension methods cannot be used to mix in property definitions (or implement interface...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.