Multi-level interfaces -- are they possible?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Multi-level interfaces -- are they possible?

  1. #1
    Join Date
    Jan 2006
    Location
    Bellevue, WA
    Posts
    9

    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?

  2. #2
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    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

  3. #3
    Join Date
    Jan 2006
    Location
    Bellevue, WA
    Posts
    9
    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.

  4. #4
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    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

  5. #5
    Join Date
    Jan 2006
    Location
    Bellevue, WA
    Posts
    9
    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

  1. Interfaces Inheriting from Interfaces
    By Larry Hunter in forum .NET
    Replies: 1
    Last Post: 01-26-2003, 11:45 PM
  2. Multi level inheritance
    By Ramkumar in forum Java
    Replies: 1
    Last Post: 12-21-2000, 12:21 PM
  3. Setting the security level of a private key
    By Juan Carlos Pérez Aguayo in forum VB Classic
    Replies: 0
    Last Post: 11-30-2000, 02:46 PM
  4. Setting the security level of a private key
    By Juan Carlos Pérez Aguayo in forum VB Classic
    Replies: 0
    Last Post: 11-30-2000, 02:46 PM
  5. 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center