Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are many developers opposed to using the "protected" modifier in OOP?
    text
    copied!<p>A co-worker of mine is taking an <em>Introduction to Object Oriented Programming</em> class and was asked a discussion question by his professor:</p> <blockquote> <p><strong>Why are many developers opposed to using the "protected" modifer on/within classes?</strong></p> </blockquote> <p>When the question was brought up at lunch, my co-workers and I couldn't think of reasons why someone might be <em>opposed</em> to using the <code>protected</code> modifier on a class. Setting the premise of the question aside (which assumes that many developers are in fact opposed to the <code>protected</code> modifier; are they?), we tried to figure out why.</p> <p>Personally, the only times that I've used the <code>protected</code> access modifier on a class is when I've written code that I might want to supplement in a test environment. For example, I might write a base class with no debugging information and then create a new class for testing, inheriting from the base class and overwriting its methods to add in debug output code before/after the base method calls. I suppose I could just as easily use a design that involves interfaces and dependency injection to accomplish the same goal, but my only experience with <code>protected</code> has been for testing purposes. In this case, the only reason to avoid <code>protected</code> is because you can accomplish the same thing in better ways.</p> <p>Why might developers be opposed to using the <code>protected</code> modifier in their OOP design?</p> <p><em>NOTE: Because the professor is asking a general OOP question not specific to any one language, I'm not sure if answers might be weighted differently because of different implementations of <code>protected</code> in C#, Java, etc..</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload