What are some ways to obfuscate or limit access to public members of a class?
The motivation behind doing this is that I would like to be able to inline
a method, but it needs access to other members in the class, which requires them to be public
, however I would prefer these members to be anything but public
, but since they must be public
, I am looking for ways to obfuscate or limit access to them.
Here is an example of such a case where I would prefer preferablyPrivateLock
to be private:
class SomeClass
{
val preferablyPrivateLock = ReentrantLock()
inline fun <R> fancyInlineFunction(function:()->R):R
{
preferablyPrivateLock.lock()
try
{
return function()
}
finally
{
preferablyPrivateLock.unlock()
}
}
}
P.S. I know this seems like bad OO design; hope this question doesn't cost me any reputation...