[Lazarus] TImage - Getting image properties in 'canvas space'
Reimar Grabowski
reimgrab at web.de
Thu Apr 19 14:39:47 CEST 2012
On Thu, 19 Apr 2012 10:21:12 +0200
Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:
> C# in .NET
> and Java etc all have support for what is now know as Reflection. They
> have full access to everything defined in a class.
At least in Java reflection does not grant you access to everything defined in a class in the general case. And its primary purpose is not to access members that are protected/private. You are correct that it can be done using reflection but you must be very explicit about it.
In general reflection does not change standard Java visibility rules.
Normally you use getField/getMethod which only grant you access to visible members. If you need more information you call getDeclaredField/getDeclaredMethod which gives you information even about protected/private members but does not enable you to access them. Only when you call setAccessible(true) on this member you disable Javas access checks for this member.
So in general reflection does not violate OOP principles and it is used like this most of the time for example to dynamicaly instantiate classes by name.
It is possible to access members that should be hidden but you must enable access to every protected/private member you want to access explicitly.
You are still working outside of OOP principles if you do this and are forced to jump through some hoops before Java grants you access to what should be hidden.
R.
More information about the Lazarus
mailing list