answersLogoWhite

0

What is interface in oops?

Updated: 12/12/2022
User Avatar

Wiki User

12y ago

Best Answer

An object is the most primitive element of a program written in the OOP language.A method of an object defines the set of operations that the object will execute when a message corresponding to the method is received by the object.The binding of a message to an method is dynamic. The entire collection of methods of an object is called the "message interface" or " message protocol".

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

An interface provides the means with which to interact with a class in a controlled manner. All classes have at least one interface but can have as many as three. The private interface is only accessible to the class itself and to friends of the class. The protected interface is the same as private but is also accessible to derivatives of the class. The public interface is accessible to any code. Every class member must belong to one (and only one) of these three interfaces.

The main purpose of a class is to encapsulate one or more invariants -- variables that must remain in a valid state at all times. As an example, a vector object must acquire a memory resource to hold an array. In addition, it must keep track of the amount of memory currently allocated to the array as well as the number of elements that are allocated within the array. All three must be kept in sync with each other such that the amount of memory allocated is equal to or greater than the number of elements. All three must work together to form an invariant. If we declare any of these variables public or protected, then we risk external code invalidating the invariant, thus all invariants must be declared private and all member functions that operate upon those invariants must work together to maintain the validity of the object, regardless of whether those members are part of the private, protected or public interfaces. In addition, we must also ensure that all friends of the class maintain the object's validity.

Since only the class itself and friends of the class have access to the private interface, we can more easily maintain an object's validity. The class constructor's ensure the invariant is correctly initialised while its mutators (assignment operators) ensure the invariant is correctly updated. In this way we do not have to continually test the validity of the invariant -- it is fully encapsulated by the operators themselves.

Of course a vector object wouldn't be much use if we didn't provide a public interface. Most accesses are read-only, thus we can provide constant public accessors so consumers can determine the size of the vector (the number of elements currently allocated) and the amount of reserved memory (the array size minus the vector size). We can also provide a subscript operator so users can examine the individual values stored in the array. The values are not part of the invariant, thus we can provide both constant and non-constant accessors so user can change the values. We can also include range-checked operators to ensure consumers do not attempt to access values beyond the scope of the array.

With a well-defined interface, we can be sure that our objects remain valid at all times and minimise the number of runtime checks we need to perform, thus our code becomes more robust and more efficient. Unfortunately, we cannot eliminate stupidity completely, but a consumer would have to go out of his way to intentionally undermine a well-designed interface. The class designer ultimately decides what can and cannot be done with their class and if a user deliberately attempts to violate an invariant at runtime, the class designer can silently veto the operation (leaving the object unchanged). If that is not possible, they may choose to throw an exception to alert the consumer instead.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is interface in oops?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a synonymm for oops?

OOPS refers to Object Oriented Programming Structure. Some common terms used in oops are # Inheritance # Polymorphism # Encapsulation # Data hiding etc..


Where can one view oops pictures?

Comedy pictures such as oops pictures can be viewed online on many websites or in some funny magazines. Examples of websites that contain funny oops pictures are the websites izismile and ebaumsworld.


How do you say uu in tabuu like ups or like oops?

Yes, like oops. (ta-boo) Its an Englsih word


What interface is an interface that uses graphics as compared to a command-driven interface?

Graphical User Interface


What does oop stand for?

OOP (Object Oriented Programming) is the implementation phase of OOD. OOD (Object Oriented Design) is a philosophy that considers things as objects that have attributes and methods. There can be public attributes and methods, and there can be private attributes and methods. The public interface is used to design the relationship between the object and its users, while the private interface is used to design the implementation of how that object works. If done correctly, the private implementation can be changed without requiring any change to the public interface or to its users. Often, a new object can be defined as a derivation of some other object, such as an officer is an employee. The derivation would add the necessary public and private aspects of an officer while inheriting the prior implementation of the public and private aspects of an employee.

Related questions

Oops you will smile?

oops, i rather not.


What is a four letter word for oops?

oops


What is full form oops?

Oops ! I did it again.


Why oops what are oops?

Simply - "OOPS is a methodology for building the software applications."-


How do you write oops in french?

The same as you do in English: Oops.


What is the new series Oops about?

it means that somebode had an oops you retard!!!


The wrong thing to say while performing brain surgery?

Oops


When was Oops TV created?

Oops TV was created on 2009-02-16.


When did Oops TV end?

Oops TV ended on 2010-02-27.


When was Oops - Oh My - created?

Oops - Oh My - was created on 2002-01-15.


What album is the song Oops...I Did It Again by Britney Spears on?

"Oops!...I Did It Again" by Britney Spears is the first song on her second studio album Oops!...I Did It Again.


When was oops you did it again released?

The single "Oops!...I Did It Again" was released on March 27, 2000.