Solved

Regarding class construction

Posted on 2004-08-31
12
188 Views
Last Modified: 2010-03-31
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??

0
Comment
Question by:sudhakar_koundinya
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11949216
why aren't you using a common interface?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 11949230
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
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11949235
Because of lack of co-ordination we  have initially, we have developed the classes individually. :-(
0
 
LVL 92

Expert Comment

by:objects
ID: 11949252
> Because of lack of co-ordination we  have initially, we have developed the classes individually. :-(

tsk tsk :)

0
 
LVL 6

Expert Comment

by:expertmb
ID: 11949257
>>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
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 11949262
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

Expert Comment

by:sciuriware
ID: 11949294
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
 
LVL 6

Expert Comment

by:expertmb
ID: 11949395
using common interface is better option, as suggested by objects.
0
 
LVL 3

Expert Comment

by:RuadRauFlessa
ID: 11949397
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11950335
>>So how can we develop the interface??

Please post classes with empty methods in both cases
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11950743
OK that model solved my problems :)
0
 
LVL 92

Expert Comment

by:objects
ID: 11950749
excellent :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert ArrayList of custom objects to JSON 4 53
count7 challenge 12 70
changeXy challenge 13 58
topping2 challenge 13 63
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now