Solved

Regarding class construction

Posted on 2004-08-31
12
198 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven example error 3 52
custom annotations 9 32
object oriented programming comparison 5 55
MySQL  on Tomcat 8 29
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

920 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

17 Experts available now in Live!

Get 1:1 Help Now