-
Multi-level interfaces -- are they possible?
I have a business object with about 10 classes, only one of which is Remoted and available to the web client (a "Controller" class with pass-through stubs to its peer classes). The client accesses the Controller class via an IController interface. It works fine except the interface is only one level deep, which will become more of a problem as the application grows. I'd love to be able to group related method calls into their own category/namespace/interface so that I could call IController like so:
IController.LoanFunctions.GetLoanInfo()
IController.ReportFunctions.GetDailyReport().
I've tried using abstract classes, using nested interfaces (which apparently aren't supported in C#) and everything else I can think of. I haven't found a way to accomplish this while remoting only one object. Any ideas?
-
instead of is-a you can use the has-a approach.
Inside the controller class create (private) instances of the other classes, and expose them as public properties.
Will that work for you?
Marco
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
Not sure if this is exactly what you were suggesting, but I ended up splitting Controller into separate classes and having a method return instances of those classes:
public class Controller : MarshalByRefObject,
IController
{
[controller-specific methods]
IXYZInterface GetXYZInterface()
{
return new XYZStubs();
}
}
Then I made a new class containing all the XYZ method stubs:
class XYZStubs : MarshalByRefObject,
IXYZInterface
{
[methods]
}
The only thing I don't like about this approach is that I believe any time a SingleCall SAO (like Controller) returns new instances of a class, the returned classes are treated as CAOs with a default lifetime of 5 minutes. I'd rather not deal with lease management when all I want is a single call for both Controller and the class references returned from it.
Last edited by Frefaln; 01-19-2006 at 04:20 PM.
-
I woudn't create a new class every time:
public class Controller : MarshalByRefObject,
IController
{
[controller-specific methods]
private IXYZInterface m_ixyz; // keep a local instance
IXYZInterface GetXYZInterface()
{
if (m_ixyl == null) m_ixyz = new XYZStubs();
return m_ixyz;
}
}
Marco
Last edited by mstraf; 01-19-2006 at 08:44 PM.
Reason: pressed Return too soon...
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
The Controller class is SingleCall so it really wouldn't matter if I instantiated a new XYZ class every time, the Controller itself only lives for one method call and is then marked for GC.
Still, your suggestion got me thinking and I think this is the way to go for now. I haven't looked into VS.NET 2005 yet to see if it supports nested interfaces (if so, I'll be jumping for joy).
Similar Threads
-
By Larry Hunter in forum .NET
Replies: 1
Last Post: 01-26-2003, 11:45 PM
-
By Ramkumar in forum Java
Replies: 1
Last Post: 12-21-2000, 12:21 PM
-
By Juan Carlos Pérez Aguayo in forum VB Classic
Replies: 0
Last Post: 11-30-2000, 02:46 PM
-
By Juan Carlos Pérez Aguayo in forum VB Classic
Replies: 0
Last Post: 11-30-2000, 02:46 PM
-
By Lim Wing Hoe in forum Java
Replies: 6
Last Post: 10-25-2000, 01:06 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks