473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interfaces design question

I have a base class (say, BaseUser) in my class library that 3 other classes
derive from:

UserTom
UserDick
UserHarry

Additionally, a fourth class that contains some administrative functions has
a method, SaveUser, that takes one of my derived classes as an argument.

Ideally, I would like to take a "generic" (read - base) object in as the
argument then determine at runtime what the object is and act accordingly.
The way I see it now, I would have to write 3 overloaded methods, each
taking a different BaseUser derived class:

SaveUser(user UserTom)
SaveUser(user UserDick)
SaveUser(user UserHarry)

When instead in my fourth class I would rather have:
SaveUser(user BaseUser)

Being a C# n00b, I am unclear as to the best design pattern for this
situation. I think it clearly is a case for an Interface (each class shares
the exact same fields and members). Should I include a SaveUser method
within the interface and implement it in each derived classes? this doesnt
seem right to me, as the implementations across the board will be exactly
the same.

Am I making any sense? Can someone steer me in the right direction?

Nov 15 '05 #1
1 1086
My first guess is that you are confusing different objects with
inheritance. Inheritance implies a specialization. Objects can have
state
so that you can identify an object as Tom, Dick and Harry.

http://www.geocities.com/jeff_louie/oop.htm

Regards,
Jeff
I have a base class (say, BaseUser) in my class library that 3 other

classes
derive from:

UserTom
UserDick
UserHarry<

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #2

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

Similar topics

1
2183
by: baylor | last post by:
In C#, an interface cannot mark any method as static. i'm told the ILASM supports it but i've never tested that Two questions. First, why? OK, i've heard the reason about interfaces being...
1
1140
by: Fuzzy | last post by:
The thread on 'why NOT to use interface?' has provoked a question - but I'll start a new thread.... Is there any performance difference that anyone is aware of between using interfaces for...
2
1164
by: raffelm | last post by:
Bear with my while I try to explain... I've created these two interfaces: public interface ILoggingEvents { event LoggingWindowClosing OnClosing;} public interface ILogging { ... } I then...
12
12447
by: Anders Borum | last post by:
Hello! I was wondering why we're allowed to define interfaces as internal, when all the members of the interface, when implemented in a class, are made public? I know that interfaces serve as...
17
2329
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component...
18
1961
by: _dee | last post by:
Question about best use of interfaces: Say there's a 'Master' class that needs to implement a few interfaces: class Master : I1, I2, I3 { } The actual code already exists in smaller...
3
1550
by: pratham | last post by:
Hi, I was seeing code of PetShop 2.0 and find is quite .. differnet design and architecture .. too much of clutter in classes .. order class using and Iorder and Iorder using an orderInfo and...
22
2062
by: RSH | last post by:
Hi, I have been reading on interfaces working on samples I've run across on the web. For the life of me I cannot seem to grasp them. It appears to me that interfaces are simply blueprints to...
27
3817
by: jm | last post by:
I am having trouble understanding the purposes of an interface, even though the concept of interfaces is around me all the time (user interface, for example). I'm just not understanding software...
18
2371
by: Tony | last post by:
class Interface { public: virtual void DoItNow()=0; }; class A: public Interface { public: void DoItNow(); // satisfies interface explicitly
0
7202
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,...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7458
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...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.