Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
In which case would you choose a static inner class?
In which case would you choose a static inner class?
✍: Guest
Interesting one, static inner classes can access the outer class's protected and private fields. This is both a positive and a negitive point for us since we can, in essence, violate the encapsulation of the outer class by mucking up the outer class's protected and private fields. The only proper use of that capability is to write white-box tests of the class -- since we can induce cases that might be very hard to induce via normal black-box tests (which don't have access to the internal state of the object). Second advantage,if I can say, is that, we can this static concept to impose restriction on the inner class. Again as discussed in earlier point, an Inner class has access to all the public, private and protected members of the parent class. Suppose you want to restrict the access even to inner class, how would you go ahead? Making the inner class static enforces it to access only the public static members of the outer class( Since, protected and private members are not supposed to be static and that static members can access only other static members). If it has to access any non-static member, it has to create an instance of the outer class which leads to accessing only public members.
2012-09-07, 2561👍, 0💬
Popular Posts:
In which event are the controls fully loaded ? Page_load event guarantees that all controls are full...
What are shared (VB.NET)/Static(C#) variables? Static/Shared classes are used when a class provides ...
What is the difference between delegate and events? ã Actually events use delegates in bottom. But ...
How can I use tables to structure forms Small forms are sometimes placed within a TD element within ...
What is the concept of XPOINTER? XPOINTER is used to locate data within XML document. XPOINTER can p...