How about using interfaces to expose a subset of the functionality?
Here is one way.

interface Bar
{
  Meth1();
  Meth7();

}
class Foo:Bar
{
  static Bar getBar()
  {
     return (Bar)new Foo()
  }
  static Foo getFoo()
  {
     return new Foo();
  }
  private Foo()
  {
  }
  Bar.Meth1(){
        Meth1();
  }
  Bar.Meth7() {
        Meth7();
  }
  Meth1(){
  }
  .
  .
  Meth7(){
  }
}

class TestFooAndBar {
        Foo myFoo = Bar.getFoo();
        Bar myBar = Bar.getBar();

        myFoo.Meth1 //works
        myFoo.Meth5 //works

        myBar.Meth1 //works just like the myFoo call above
        myBar.Meth5 //oops, the method doesn't exist

}

-----Original Message-----
From: Chris Jenkin [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 09, 2002 4:50 PM
To: [EMAIL PROTECTED]
Subject: [DOTNET] General object question?


I have a class that has grown quite large. It has come to pass that I would
like to expose a very small subset of this class' functionality as another
class(?). Here's the example:

I have class Foo with 10 methods lets say (Meth1 - Meth10)

class Foo {
        Meht1 {
        }

        Meth2 {
        }

        etc...
}

What I would like to do is something like the following:

1) Create a class that exposes only a portion of the functionality of class
Foo, Bar is a good name for this.

class Bar : inherits Foo (?) {

        Meth1 {
        }

        Meth7 {
        }
}

2) Give the "user" a choice of which class they would like to use depending
on the functionality they need.

class TestFooAndBar {
        Foo myFoo = new Foo();
        Bar myBar = new Bar();

        myFoo.Meth1 //works
        myFoo.Meth5 //works

        myBar.Meth1 //works just like the myFoo call above
        myBar.Meth5 //oops, the method doesn't exist

}

Is this doable? I don't really want to rewrite Foo into a new Bar, because
Bar would need about 90% of the internal Foo code to work properly and I
would like to avoid big changes to Foo as it is already implemented in a
large volume of code. What to do?

TIA
CJ


You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to