Results 1 to 7 of 7
- 08-20-2013, 09:05 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
apply interface to a different class
say, I have a client code I want to implement
UserStuff us = new UserStuff();
boolean result = us.isChrome();
isChrome method is an interface method of CheckBrowser class.
Is it possible to implement like this using Factory method pattern or something.
Of course I need to add necessary methods like getter and setter or some else.
- 08-20-2013, 09:56 AM #2
Re: apply interface to a different class
Maybe someone smarter than me will figure it out, but I don't think there's nearly enough information there for you to get meaningful help. You may need to supply more context.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 08-20-2013, 10:13 AM #3
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: apply interface to a different class
I'm not smarter and I did not figure it out, but the answer to the question is easy: yes. The reason is simple: anything is possible.
That's why that particular question is not interesting at all. The real question is: is it a good idea? To be able to answer that, the example needs to be made a whole lot more clear."Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 08-20-2013, 11:02 AM #4
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
Re: apply interface to a different class
thanks for the replies. I understand that it does not provide enough information.
Only thing that is clear at this point is the client part.
What confuses me most is that "isChrome" is not a member of the class "UserStuff".
then how can it be possible to achieve such implementation of the method to an object of "UserStuff"???
- 08-20-2013, 11:07 AM #5
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: apply interface to a different class
Still no idea what you're talking about. But it seems like your understanding of classes, interfaces and objects simply needs a bit of freshening up.
Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)
Interfaces (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 08-20-2013, 11:44 AM #6
Member
- Join Date
- Jan 2011
- Posts
- 14
- Rep Power
- 0
Re: apply interface to a different class
right. it is my understanding. I need clarify that.
the only methods that an object can call are those defined in the same class? Am i misunderstanding?Last edited by soichi; 08-20-2013 at 11:47 AM.
- 08-20-2013, 10:18 PM #7
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: apply interface to a different class
First, do you have access to the class code UserStuff? If so, then implement the interface or
extend the class and implement the interface. In the subclass case, only the subclass will know about
isChrome.
Or write a wrapper to the class UserStuff and implement the interface on the wrapper. Then when the isChrome
method is invoked, use the state of the UserStuff object to return whatever is meaningful. Of course, the latter
method does not permit passing an instance of the wrapper class to some method that expects a UserStuff object.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
Interface Inheritance : create class that implements the interface
By Zulkifli_Rahman in forum New To JavaReplies: 1Last Post: 07-08-2012, 06:23 PM -
Does an anonymous class have to extend a class or implement an interface ?
By fatabass in forum New To JavaReplies: 15Last Post: 02-05-2012, 12:15 AM -
E:\IT 215 Java Programming\public class Inventory.java:39: class, interface, or enum
By tlouvierre in forum New To JavaReplies: 14Last Post: 05-28-2009, 06:44 AM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 08:04 AM -
Class inside an Interface
By $hr!k@nt in forum New To JavaReplies: 1Last Post: 12-21-2007, 11:56 AM
Bookmarks