58.0k views
5 votes
Requirement that all objects be completely encapsulated is too stringent, what is one way to relax this requirement?

User AdamGold
by
8.2k points

1 Answer

0 votes

Final answer:

One way to relax the requirement of complete encapsulation in object-oriented programming is to use protected access modifiers allowing limited access to subclasses.

Step-by-step explanation:

When it comes to object-oriented programming, the requirement of complete encapsulation can sometimes be too stringent. One way to relax this requirement is to use the concept of protected access modifiers.

Protected access allows subclasses to access the attributes and methods of their superclass, without allowing access to other classes. By using protected access, you are still providing some level of encapsulation while allowing for limited access.

For example, let's say you have a class called Animal, and you want to create a subclass called Dog. By using the protected access modifier, you can give the Dog subclass access to the attributes and methods of the Animal class but restrict access to other classes.

User Koushik Das
by
7.9k points