IS THE PURPOSE OF AN INTERFACE TO HIDE INFORMATION?

jacob rasel

Total Post:88

Points:616
Posted by  jacob rasel
OOPS 
 1408  View(s)
Ratings:
Rate this:

Given that interfaces are also used to help hide information, giving the user only a subset of the possible methods they are allowed to use, and, let's say, I have a Person class and interface IPerson.

Now in main, I'm allowed to do

IPerson testy = new Person();

or

Person testy = new Person();

So really I'm not restricted from using Person still. So how does the interface truly hide data?

  1. Vijay Shukla

    Post:100

    Points:700
    Re: Is the purpose of an interface to hide information?

    Hey Jacob Rasel!

    What if You dont have that Person class.

     Object obj = loadObject();

     

     if(obj is IPerson) {

     

      IPerson person = (IPerson) obj;

     

     }

    or

      IPerson person = loadPerson();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!