answersLogoWhite

0


Best Answer

Interfaces are designed to do exactly that: to interface or to interact. In object-oriented programming languages such as C++, you can incorporate up to three different interfaces per class. The private interface is accessible only to the class itself and to friends of the class. The protected interface is the same as the private interface but is also accessible to derivatives of the class. The public interface is accessible to any code.

For one interface to interact with another interface, the first must have access to the second. If the first is a friend of the second or both are members of the same class, the first has unrestricted access to the private, protected and public interfaces of the second. If the first is derived from the second but is not a friend, the first only has access to the protected and public interfaces of the second. If the first is completely separate from the second, the first only has access to the public interfaces of the second.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can access an interface from another interface and how to access from a class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is Iterator a class or Interface?

Its an interface.


Is interface class a valid term?

Yes. An interface in essence is a java class and so you can use the term interface class. But, using the term class along with the term interface can cause ambiguity or misunderstandings among novice java developers. So, using the term "Interface" along would suffice to refer to a type of class which is the "Interface"


What is meant by interface of a class and implementation of a class in c plus plus?

The interface of a class is defined as being the methods that allow the outside world to interact with objects instantiated from that particular class type. That interface may be declared within the class itself or it may be inherited from base classes, or it may be some combination of the two. The interface may also be virtual or even pure-virtual, either in whole or in part. The implementation determines how that interface operates. Although the interface and the implementation go hand-in-hand they are treated separately because a derived class can override the generic interface exposed by the base class in order to provide a more specialised implementation of the base class interface, as well as provide new interfaces of its own. The generic interface needn't be virtual in order to be overridden, but it must be virtual in order to allow polymorphic behaviour. Where the base class cannot provide an implementation because it is intentionally abstract and therefore relies solely upon a derived implementation, it will provide a pure-virtual interface that absolutely must be implemented by all derivatives. If a class declares or inherits a pure-virtual interface with no implementation, that class automatically becomes abstract. Only classes that provide a complete implementation for all pure-virtual interfaces (including any generic implementations inherited from base classes derived from the base class), can actually be instantiated. When calling a base class method from a non-member function, one would rightly expect the implementation of the derived class to be executed. In order to achieve this, the generic interface must be virtual and the virtual table ensures the call is routed to the correct implementation. Without this, only the base class method can be called, which may result in unexpected behaviour in the derived class since the base class would be unaware of its specific behaviour. While it is possible to allow a base class to gain access to a derived class interface without exposing a virtual interface, this can only be done when the base class already knows exactly what type of derivative to expect. Knowing the type of its derivative allows the base class to make an explicit dynamic cast of itself in order to call the appropriate interface. But it cannot predict the future: if you derive a new class of object that it knowns nothing about, it cannot gain access to its specialised interface. Even dynamic casting is impossible without knowing what type of object to cast to. Virtual interfaces overcome this problem by ensuring that no matter what derivatives are created either now or in the future, the base class can access each of their specific implementations through just one generic interface, without the need for any dynamic casting (which is almost always a sign of poor design). When a base class interface is routed to a derived class implementation, that specific implementation has complete access to the derived class' interface. Thus interfaces that the base class doesn't even know exist can be implemented via calls through the base class' virtual interface which is the only interface the base class really needs to know anything about. To put it another way, all derivatives of the same base class can be treated just as if they were the base class itself, with a common, generic interface, and yet each instance can exhibit entirely different behaviour, according to the specific implementations defined by each derivative. That is, one interface/multiple implementations. Derived class implementations may also, optionally, call any base class method and access any base class variable (other than the base class' private members, of course). This makes it possible to provide a generic implementation of the virtual interface that can then be augmented or replaced completely by the more specific implementations of the derived interface. Even pure-virtual methods, which are normally not implemented in an abstract base class, can provide a generic implementation where appropriate. Although the implementation cannot be inherited, the interface must be inherited because it is virtual. However, once a derived class implements a pure-virtual interface, that implementation can then be inherited by its derivatives, to be further specialised and or augmented as necessary.


What is mean by class access?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.


Abstract class vs interface?

Comparison between an Abstract Class and an Interface:While an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. Another way interfaces differ from abstract classes is that interfaces have very little flexibility in how the methods and variables defined in the interface are declared. These rules are strict:

Related questions

Interface can be defined inside another class?

yes ,interface can be defined inside another class


Why protected access specifier is not in interfaces?

Because an interface is like a contract/skeleton which decides what the implementing class has to do. So, if any entity in an interface is protected, they would not be available to the class that is implementing the interface. Hence, all the variables and methods declared inside an interface are public by default


Is Iterator a class or Interface?

Its an interface.


Is interface class a valid term?

Yes. An interface in essence is a java class and so you can use the term interface class. But, using the term class along with the term interface can cause ambiguity or misunderstandings among novice java developers. So, using the term "Interface" along would suffice to refer to a type of class which is the "Interface"


What is meant by interface of a class and implementation of a class in c plus plus?

The interface of a class is defined as being the methods that allow the outside world to interact with objects instantiated from that particular class type. That interface may be declared within the class itself or it may be inherited from base classes, or it may be some combination of the two. The interface may also be virtual or even pure-virtual, either in whole or in part. The implementation determines how that interface operates. Although the interface and the implementation go hand-in-hand they are treated separately because a derived class can override the generic interface exposed by the base class in order to provide a more specialised implementation of the base class interface, as well as provide new interfaces of its own. The generic interface needn't be virtual in order to be overridden, but it must be virtual in order to allow polymorphic behaviour. Where the base class cannot provide an implementation because it is intentionally abstract and therefore relies solely upon a derived implementation, it will provide a pure-virtual interface that absolutely must be implemented by all derivatives. If a class declares or inherits a pure-virtual interface with no implementation, that class automatically becomes abstract. Only classes that provide a complete implementation for all pure-virtual interfaces (including any generic implementations inherited from base classes derived from the base class), can actually be instantiated. When calling a base class method from a non-member function, one would rightly expect the implementation of the derived class to be executed. In order to achieve this, the generic interface must be virtual and the virtual table ensures the call is routed to the correct implementation. Without this, only the base class method can be called, which may result in unexpected behaviour in the derived class since the base class would be unaware of its specific behaviour. While it is possible to allow a base class to gain access to a derived class interface without exposing a virtual interface, this can only be done when the base class already knows exactly what type of derivative to expect. Knowing the type of its derivative allows the base class to make an explicit dynamic cast of itself in order to call the appropriate interface. But it cannot predict the future: if you derive a new class of object that it knowns nothing about, it cannot gain access to its specialised interface. Even dynamic casting is impossible without knowing what type of object to cast to. Virtual interfaces overcome this problem by ensuring that no matter what derivatives are created either now or in the future, the base class can access each of their specific implementations through just one generic interface, without the need for any dynamic casting (which is almost always a sign of poor design). When a base class interface is routed to a derived class implementation, that specific implementation has complete access to the derived class' interface. Thus interfaces that the base class doesn't even know exist can be implemented via calls through the base class' virtual interface which is the only interface the base class really needs to know anything about. To put it another way, all derivatives of the same base class can be treated just as if they were the base class itself, with a common, generic interface, and yet each instance can exhibit entirely different behaviour, according to the specific implementations defined by each derivative. That is, one interface/multiple implementations. Derived class implementations may also, optionally, call any base class method and access any base class variable (other than the base class' private members, of course). This makes it possible to provide a generic implementation of the virtual interface that can then be augmented or replaced completely by the more specific implementations of the derived interface. Even pure-virtual methods, which are normally not implemented in an abstract base class, can provide a generic implementation where appropriate. Although the implementation cannot be inherited, the interface must be inherited because it is virtual. However, once a derived class implements a pure-virtual interface, that implementation can then be inherited by its derivatives, to be further specialised and or augmented as necessary.


Can interface extends another interface?

yes of cause interface is use in java at the place of multiple inheritance .o as like multiple inheritance u can extends interface class to other. and another think is interface contain abstract method i.e method with no defination so u can use it without any error.


Why instance in abstract or interface?

we can make object of interface but in abstract we can not make object of it interface ab= new Classs(): in interface we maintain multiple inhetence by use of obj of interface we if inherit two class have same fun then we give the name of that interface and call the pertucular that fun interface ab= new class() ab.add(); but in Astract Class we cannot make object of it only class class wich inherit it can make object class ab2= new Class(); and by obj we call function of drived class ob2.add();


What is mean by class access?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.


What is mean by accessibility?

Class access is the ability for any given class to access the functions of another class. Private access limits access to data and code just to the class that contains the private access modifier. The so-called "default" access grants private access, as well as access to any class in the same package. Protected access grants the same as "default" access, and also allows subclasses to access the code and data. Public access allows any class in any package to access the code and data.


Abstract class vs interface?

Comparison between an Abstract Class and an Interface:While an abstract class can define both abstract and non-abstract methods, an interface can have only abstract methods. Another way interfaces differ from abstract classes is that interfaces have very little flexibility in how the methods and variables defined in the interface are declared. These rules are strict:


What is similarities between Abstract Class and Interface?

If a class has one abstract method ,the class has to be an abstract class.Methods can be implemented in abstract class.Whereas a interface is like a abstract class...the only difference being that the methods are never implemented in Interface.


How Can a derived class access an integer variable of base class in qt?

The best design strategy would be to provide a protected accessor (getter) that returns the variable either by value or by constant reference. If the derived class needs to mutate the variable, then provide a protected mutator (setter). Only derived classes have protected access to their base classes. However, derivatives can also lower that access to private with respect to their own derivatives, if desired. Even if the variable does not represent a class invariant, it's still best to provide an interface rather than expose an implementation detail outside of the class, whether that exposure is public or protected. In this way the implementation detail may be changed at a future time without affecting any of the consumers of your class (including derivatives), since they will all be using the public or protected interface. So long as that interface remains unchanged, the scope of your internal changes is limited to the class itself, thus you won't break any code that uses your class. If your class already provides a public interface to the variable, then your derived class can obviously make use of that as well. You only need a protected interface when no public interface is provided.