Regarding class construction

Hello All,

I am I am facing a situation where I am failing to put common interface to  2 classes.

Class A is developed by me and Class B is developed by my US collegue.

Both are working models and giving correct results.

Now my problem is, these two solutions need to have common  interface. But the method implementation  of these two classes are entirely different.

So how can we develop the interface??

LVL 14
sudhakar_koundinyaAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
you coould also add a new common interface to each of the classes to map to the differing interface.

interface Common
{
   public void doSomething();
}

class A implements Common
{
   public void doSomething()
   {
      doSomethingTheAWay();
   }

   public void doSomethingTheAWay()
   {
      ...
   }
}

class B implements Common
{
   public void doSomething()
   {
      doSomethingTheBWay();
   }

   public void doSomethingTheBWay()
   {
      ...
   }
}
0
 
objectsCommented:
why aren't you using a common interface?
0
 
objectsConnect With a Mentor Commented:
interface Common
{
   public void doSomething();
}

class AWrapper implements Common
{
   private A Wrapped;

   public void doSomething()
   {
      Wrapped.doSomethingTheAWay();
   }
}

class BWrapper implements Common
{
   private B Wrapped;

   public void doSomething()
   {
      Wrapped.doSomethingTheBWay();
   }
}
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
sudhakar_koundinyaAuthor Commented:
Because of lack of co-ordination we  have initially, we have developed the classes individually. :-(
0
 
objectsCommented:
> Because of lack of co-ordination we  have initially, we have developed the classes individually. :-(

tsk tsk :)

0
 
expertmbCommented:
>>But the method implementation  of these two classes are entirely different.
tht is the good thing of interface.  you implement the method in your way and your colleague implement in his own way. if you carefully look at collection package you willcome to know how good these interface concept is.
0
 
sciuriwareCommented:
sudhakar_koundinya, you ask a lot questions but the titles are unusable for retrieval.
Can you please title such that one knows what the essence of the question is from the outside?
I guess you want to search for older solutions too ....
Just look around.

;JOOP!
0
 
expertmbCommented:
using common interface is better option, as suggested by objects.
0
 
RuadRauFlessaCommented:
If you can perhaps give us a description of the methods that you would like to use in the interface? I take it that perhaps they take diffirent paramaters and such.
0
 
CEHJCommented:
>>So how can we develop the interface??

Please post classes with empty methods in both cases
0
 
sudhakar_koundinyaAuthor Commented:
OK that model solved my problems :)
0
 
objectsCommented:
excellent :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.