Solved

Regarding class construction

Posted on 2004-08-31
12
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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