[Lazarus] TImage - Getting image properties in 'canvas space'

Martin Schreiber mse00000 at gmail.com
Thu Apr 19 10:26:50 CEST 2012


On Thursday 19 April 2012 09:52:30 michael.vancanneyt at wisa.be wrote:
> On Thu, 19 Apr 2012, Graeme Geldenhuys wrote:
> > On 19 April 2012 00:04, Alberto Narduzzi <albertonarduzzi at yahoo.com> 
wrote:
> >> An interface to a class (or its concept, anyway) is there for a reason.
> >> And you should adhere to. I may also say that if you need to access a
> >> protected, or private for what is worth, member of a (library...) class,
> >> then you should revise your code... because either you're using the
> >> wrong class, or your problem can be solved in a different, possibly more
> >> elegant, and surely more OO compliant way ;-)
> >
> > I totally disagree...  :)
> > type
> >  // Friend class to get access to protected methods
> >  THackCustomEdit = class(TCustomEdit);
>
> The Hack says it all. Here you are working outside regular OOP rules.
>
> The correct way would have been an implementation for each descendent of
> TCustomEdit.
>
> You just took a shortcut. Nothing wrong with that by itself, but basing an
> argument about general OOP rules on a shortcut implementation is incorrect
> reasoning.
>
> In a system with stricter rules, you would have had to solve it
> differently.
>
May I repeat the idea of "friend units"?
While designing a complex framework like Lazarus, fpGUI or MSEgui there 
constantly is the need to access low level functions from other classes. Now 
one has the options to write the whole framework in a single unit (ex. 
db.pas), to make most of the class elements public or to use local alias type 
definitions.
For me public class elements should be "user suitable" and safe. I don't think 
it is a good idea to place elements the user of the framework normally should 
not touch to public.
And I don't think that in a project of that dimension it is possible to 
maintain a completely clean OOP structure with an acceptable effort.
The introduction of "friend units" would be a simple solution. In "friend 
units" the protected class members would be visible. So if you build a 
framework and you know what you do, list the base units of the framework as 
friends of higher level units of the same framework. Users of the framework 
don't need friend units and can use the public class elements in a save 
manner.

Martin




More information about the Lazarus mailing list