• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access the method in another class ,when that method has been implemented from an interface  RSS feed

 
Sucheta Shrivastava
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have data of an organization  that has to be arranged in a tree like structure - hierarchial manner . That data i retrieve from a normal text file and an xml file. since it comes from two places i have created a common interface that has a method named readData() that reads the data from both the file from FileInput class that implemented that interface and Readxmlfile class that reads data from an xml file.

now how to obtain the data in another class that utilizes the data and  creates a tree like structure.

CODE

Interface-



Implemented Classes -




class 2 -




Class Organisation Hierarchy where i want to use the data obtained from the interface


 
Sucheta Shrivastava
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here i want to utilize  and access the data obtained from the FileInput class and Readxmlfile class into OrganisationHierarchy class
 
Sucheta Shrivastava
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to do that
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand you.  Do you mean this?
 
Tim Holloway
Saloon Keeper
Posts: 18799
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading your message title literally, an Interface is a contract - a promise. If a class implements that interface (as indicates by the "implements" in the class definition), then that class must contain an implementation of that method. The promise ust be kept. Therefore a method in any class, including some other class than the one implementing the interface can invoke that method simply by obtaining an object instance for the target class and invoking the method on that instance.

The word "access" is not a good one to use for that purpose. "Access" typically means something that you read or write to. If you with, instead to execute the method code, the proper OOP term is "invoke". It is the object-oriented equivalent o the procedure-oriented  term"call". The distinction is that in procedure-oriented languages, you are calling pure code, but in OO method invocations, there's always an associated class or object instance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!