473,756 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

advice about Interfaces

Hi,

Im starting develop a portal, and i never used interfaces in the past.

As any portal will be possible register (add), delete, modify a user.
In this portal also will be possible register(add) , delete, modify
bussiness...
I have a class called user, and another called bussiness...

Yesterday i was reading about the using of the interfaces and gives to me an
idea, but i dont know if its a good way to do:

the theme is, make 3 interfaces IRegistrable, IModifiable, IRemovable

and implement this three into the two classes, User, and Bussiness.

Inside each Interface a method following this:

IRegistrable with a method called Register()
IModifiable with a method called Modify()
IRemovable with a method called Remove()

Any advice about it?
--------
Thanks
Regards.
Josema
Nov 17 '05 #1
12 1396
"Josema" <Je******@ocu.o rg> a écrit dans le message de news:
D9************* *************** **...icrosof t.com...
the theme is, make 3 interfaces IRegistrable, IModifiable, IRemovable

and implement this three into the two classes, User, and Bussiness.

Inside each Interface a method following this:

IRegistrable with a method called Register()
IModifiable with a method called Modify()
IRemovable with a method called Remove()


But this means that you are adding the Register, Modify and Remove behaviour
to the classes, not to the Portal.

If you are thinking of having differing implementations behind the Portal,
then declaring an interface IPortal with your three methods would be
worthwhile, but apart from that, I cannot see too much point.

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #2
Hi Joanna, i dont understand when you talk about the behaviour of the
classes... I thought that if two objects has the same operations (object
person, and object bussiness can be registered, modified, removed, etc...),
could be good to make some interfaces to implement inside of them...

I dont understand if the person and the bussiness can be for instance,
registered, i dont see the relation with the portal, the portal cant be
registered....

Could you explain it a little?

Sorry for my not understanding im newbie in the using of the interfaces...

Kind Regards.
Josema.

"Joanna Carter (TeamB)" wrote:
"Josema" <Je******@ocu.o rg> a écrit dans le message de news:
D9************* *************** **...icrosof t.com...
the theme is, make 3 interfaces IRegistrable, IModifiable, IRemovable

and implement this three into the two classes, User, and Bussiness.

Inside each Interface a method following this:

IRegistrable with a method called Register()
IModifiable with a method called Modify()
IRemovable with a method called Remove()


But this means that you are adding the Register, Modify and Remove behaviour
to the classes, not to the Portal.

If you are thinking of having differing implementations behind the Portal,
then declaring an interface IPortal with your three methods would be
worthwhile, but apart from that, I cannot see too much point.

Joanna

--
Joanna Carter
Consultant Software Engineer

Nov 17 '05 #3
"Josema" <Je******@ocu.o rg> a écrit dans le message de news:
C1************* *************** **...icrosof t.com...
Hi Joanna, i dont understand when you talk about the behaviour of the
classes... I thought that if two objects has the same operations (object
person, and object bussiness can be registered, modified, removed, etc...), could be good to make some interfaces to implement inside of them...

I dont understand if the person and the bussiness can be for instance,
registered, i dont see the relation with the portal, the portal cant be
registered....
I assume from your posting address that your own language would possibly be
Spanish ?

Does that mean that I couold change your method names to :

Register - Save or Store
Modify - Change or Update
Remove - Delete

....and that these methods are for storing and retrieving objects from some
kind of database or file ?

If that is the case, then you don't want to put these methods in the objects
that you are going to do these things to; they really belong in what you
call a Portal.

Your Portal should be able to examine the objects passed to it without
having to change those objects. In .NET that means you can use reflection to
read/write values from/to the objects.

So, you just need to add the methods to your Portal like this :

interface IPortal
{
void Register(object obj);
void Modify(object obj);
void Remove(object obj);
}

Which would be used like this :

{
IPortal portal = new DatabasePortal( ); // or whatever type you want to use
...
Person person = new Person();
...
portal.Register (person)
...
}

Declaring an interface for the Portal now allows you to change the class
that you use to Register, Modify, and Remove objects.

But there is no advantage in declaring the interfaces as you suggest and
using them on the objects to be passed to the Portal.
Sorry for my not understanding im newbie in the using of the interfaces...


And I think you are trying to use them in the wrong place and for the wrong
reason :-)

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #4
I think what he means is that if you use your method, the classes go
through the task of registering themselves, whereas if you use his
means (IPortal, for example), the Portal itself handles registration of
the users/businesses. In this case, You'd have something like:

PortalClass.Reg ister(User user);
PortalClass.Mod ify(User user);
PortalClass.Rem ove(User user);

PortalClass.Reg ister(Business business)...

You get the point. Here, if businesses and users use the same code for
adding, modifying and removing, it might be helpful to use an interface
or some kind of interface to define common properties needed for
business and users to be added, etc. Thats where I'd see the
IRemovable, IModifiable, IRegistrable existing. At the same time, if a
Business is just a User with some added functionality not related to
removing, adding, or modifying, you can create the business class with
User as a base class, then you'd only have the first three method
declarations above.

Clint

Nov 17 '05 #5
I think what she means is that if you use your method, the classes go
through the task of registering themselves, whereas if you use her
means (IPortal, for example), the Portal itself handles registration of

the users/businesses. In this case, You'd have something like:
PortalClass.Reg ister(User user);
PortalClass.Mod ify(User user);
PortalClass.Rem ove(User user);
PortalClass.Reg ister(Business business)...
You get the point. Here, if businesses and users use the same code for
adding, modifying and removing, it might be helpful to use an interface

or some kind of interface to define common properties needed for
business and users to be added, etc. Thats where I'd see the
IRemovable, IModifiable, IRegistrable existing. At the same time, if a
Business is just a User with some added functionality not related to
removing, adding, or modifying, you can create the business class with
User as a base class, then you'd only have the first three method
declarations above.

Clint

Nov 17 '05 #6
Hello Joanna,

With all due respect, I don't agree with your advice this time. Josema:
Please read this post... there's some advice for you at the end.

"Joanna Carter (TeamB)" <jo*****@nospam forme.com> wrote
you don't want to put these methods in the objects
that you are going to do these things to; they really belong in what you
call a Portal.
There is nothing wrong with placing these operations within the object
themselves. Using AOP and TDD, I would do the same thing. The design is
smaller and more testable if you make an object responsible for its own
registration and storage, as long as the downstream needs of the object are
declared somewhere (either in the constructor or in the "Register" method).

Therefore, the portal would provide an interface
'IRegistrationM anager' with methods 'LookupExisting ', and 'RegisterNew' for
example.

The objects could implement an Interface for IRegisterable as:
interface IRegisterable
{
void PerformRegister (IRegistrationM anager RegMgr);
}

Then when the object is created, it can be created completely seperately
from the functions of the portal. Attaching it to the portal simply means
that the calling code passes the portal object in to the registration method
of the child object. You could create a factory method that returns
different RegistrationMan ager objects from the portal depending on a
variable that varies independently, like registration mechanism, or contract
policy, etc.

Your Portal should be able to examine the objects passed to it without
having to change those objects. In .NET that means you can use reflection
to
read/write values from/to the objects.
Reflection is a useful mechanism for some things. However, it is not a
panacea, and it is more expensive that simple pattern techniques like the
one I explained above that generate the same amount of loose coupling.


So, you just need to add the methods to your Portal like this :

interface IPortal
{
void Register(object obj);
void Modify(object obj);
void Remove(object obj);
}

Which would be used like this :

{
IPortal portal = new DatabasePortal( ); // or whatever type you want to
use
...
Person person = new Person();
...
portal.Register (person)
...
}

I would agree only if the .Register methods were polymorphically declared
within the DatabasePortal class allowing the call portal.Register (person) to
bind to a Register method that specifically binds people... and even then, I
would consider this form of coupling to be a little too tight for me.
But there is no advantage in declaring the interfaces as you suggest and
using them on the objects to be passed to the Portal.
And I think you are trying to use them in the wrong place and for the
wrong
reason :-)


And, the crux of the matter, I am concerned about these statements. You
imply that the proposed use would never be right, and I believe I've shown
that there are cases where this approach, with serious refinement, can yeild
fruit.

I think the OP is starting to stumble upon some intermediate patterns
without understanding the basic patterns first, so the description isn't
altogether collected in his or her mind.

To Josema: NOW is the time for you to read "Design Patterns Explained" by
Shalloway and Trott. Do not toss out interfaces or jump into the crutch of
using reflection until you understand how to perform Commonality -
Variability Analysis. You need to have a good idea of what methods should
be coupled together in your interfaces, and more importantly, what variation
you are attempting to encapsulate. Joanna is not wrong... you may not be
encapsulating the most sensible things. While we disagree about the
application of the methods you are using, I agree with her that you need to
approach Interfaces with an understanding of the underlying reasons for
encapsulating things... something that I'm not sure you've really got your
arms around yet.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Nov 17 '05 #7
"Nick Malik [Microsoft]" <ni*******@hotm ail.nospam.com> a écrit dans le
message de news: Mq************* *******@comcast .com...
Hello Joanna,
Hi Nick

Josema, please follow this discussion, and you will see that both Nick and I
are trying to understand your ideas and that we both have valid
interpretations . It has to be up to you to help us to help you by deciding
what you really need to know about.
With all due respect, I don't agree with your advice this time.
No problem, there are at least two schools of thought on this issue; we
obviously attended both :-)
There is nothing wrong with placing these operations within the object
themselves. Using AOP and TDD, I would do the same thing. The design is
smaller and more testable if you make an object responsible for its own
registration and storage, as long as the downstream needs of the object are declared somewhere (either in the constructor or in the "Register" method).

My main objection to this approach is that you are tying Portal behaviour to
'business' classes, thereby making it impossible to use these classes
anywhere that doesn't have a Portal concept without carrying the Portal
baggage with it.

I would agree that your suggestion is not 'wrong', just that I prefer to
keep business classes free of anything for which they need not be directly
responsible.

Having said that, it is not totally clear what Josema is actually trying to
achieve, as the original post could be interpreted in more than one way, and
addressed by more than one pattern or solution; I chose the OPF-like
solution :-)

I also think that the language Josema is using indicates persistence like
operations, when you think of Spanish words for those concepts. (??)
Reflection is a useful mechanism for some things. However, it is not a
panacea, and it is more expensive that simple pattern techniques like the
one I explained above that generate the same amount of loose coupling.
I certainly don't like to use reflection more than absolutely necessary,
preferring to implement things like the Visitor pattern for persistence
frameworks, etc.
I would agree only if the .Register methods were polymorphically declared
within the DatabasePortal class allowing the call portal.Register (person) to bind to a Register method that specifically binds people... and even then, I would consider this form of coupling to be a little too tight for me.
IMO, this is where compromise between absolute type safety and generic
mechanisms has to be evaluated for each scenario.
And, the crux of the matter, I am concerned about these statements. You
imply that the proposed use would never be right, and I believe I've shown
that there are cases where this approach, with serious refinement, can yeild fruit.
Certainly, it was never my intention to imply right or wrong, but to
demonstrate one aspect. Thanks for helping open up the discussion with other
POVs.
I think the OP is starting to stumble upon some intermediate patterns
without understanding the basic patterns first, so the description isn't
altogether collected in his or her mind.


Agreed.

Josema, please help us to help you by answering our doubts and clarifying
what it is you really want to do. :-))

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
Nov 17 '05 #8
Clint (cm******@onlin e.nospam) wrote:
I think what he means is that if you use your method, the classes go
through the task of registering themselves, whereas if you use his
means (IPortal, for example), the Portal itself handles registration of
the users/businesses. In this case, You'd have something like:

PortalClass.Reg ister(User user);
PortalClass.Mod ify(User user);
PortalClass.Rem ove(User user);

PortalClass.Reg ister(Business business)...

Hmm, here is something similar to what we were debating about in the
speaker room of a conference lately.

Consider the registration defined above and the registration defined
below from another posting.

*****
Therefore, the portal would provide an interface
'IRegistrationM anager' with methods 'LookupExisting ', and 'RegisterNew' for
example.

The objects could implement an Interface for IRegisterable as:
interface IRegisterable
{
void PerformRegister (IRegistrationM anager RegMgr);
}

*****
Our discussion in the past was related to graphics and who paints whom.
This is a very similar argument in who registers whom.

My conclusion is that there is no definite argument to either as both
have their advantages and disadvantages.

For example while it sounds good that objects are responsible for
themselves it does make for more complicated objects as they are
responsible for many many things increasing the size of the object.

On the other hand having a portal class creates a central location for
referencing thus potentially making it hard to update the Portal class.

Any insights on this issue, in either direction?

Christian Gross
Nov 17 '05 #9
Not offhand. Really, I've aloways just gone under the presumption of
"What Makes Sense" (tm). In this case, as Nick above mentioned and I
agree with, there's no real right or wrong, it just depends on your
philosophy.

Personally, I think I'd go under the rule of the Portal controlling
everything that happens to it - when something is added and removed. In
the case of modifications, that has to deal with changing the object
directly, so that would be a method within the User or Business classes
themselves.

Nov 17 '05 #10

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

Similar topics

9
2314
by: Code4u | last post by:
My colleagues and I have been discussing techniques for implementing interfaces in C++. We're looking for a mechanism similar to COM's QueryInterface, in which a certain types of objects can be queried, at run-time, for a particular interface and if it is supported, a pointer or reference to that interface passed to the caller. Two possible implementations came up, multiple inheritance and composition. Using MI the class multiply inherits...
5
3675
by: Michael McCarthy | last post by:
I want to develop plugin support for a system.montitor module I am working on. A lot of the modules will do mostly interop stuff for an older system, but I want to use it myself as well to monitor event logs and other things as I think of them... I've seen two ways of doing this, the abstract class factory, or the interface... the module logic is fairly simple, watch something -> get the result -> notify / fix / and or log it... I've...
5
1417
by: Natan | last post by:
I want to create an n-tier app and I would like an advice of you that know more than me about this. I want my app to support multiple databases in the way that when a client wants to use Oracle and not SQL server, I can easily port the data layer without touching the rest of the code. So, I have 2 ideas. 1: Take the way MS Pet Shop did (I read a LOT in many sites how this
6
1876
by: Eric Guthmann | last post by:
Hello all We have an SOA application that includes an ASP.NET webservice and WinForms client. My question is regarding the use of Add Web Reference in Visual Studio. The tool is nice because it easilly creates and updates the client-side proxies that we need to communicate with the webservice. The problem is that our webservice methods accept and return business objects and when generating the proxies, VS creates scoped versions of...
1
9650
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
13
1783
by: goodoldave | last post by:
Hey everyone, I need some advice concerning Interfaces and delegates. I would like to define a delegate inside of an interface (I know a delegate is a class but hear me out) Here is a sample: Interface A
13
3113
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those sorts of clients. Mine are all small businesses whose sites will never reach those sorts of scales. I deal with businesses whose sites get maybe a few hundred visitors per day (some not even that much) and get no more than ten orders per day....
3
1090
by: eric.burgin | last post by:
I have not heavily used interfaces in the past so I am looking for advice. An interface may not be the best solution but it was the first idea I had and was working at first. Here is the situation, I have been asked to create an application that will provide a "script" of things to say, yes/no questions to ask, information to look up etc. This could be used by multiple clients to I am creating a class library to implement the...
13
1334
by: terry.holland | last post by:
I have a three tiered CRM application (ASP.Net UI, VB.Net Business Layer & VB.Net Data Access Layer) that consists of number of classes. The application will be deployed to a number of clients. Some of our clients have no existing CRM system and are happy that our application stores Client information. Other clients have already got a CRM system and want our application for the additional functionality that it offers. These clients would...
0
9456
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
9872
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
9843
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
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
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
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.