[Kstars-devel] branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents

Jason Harris kstars at 30doradus.org
Thu Aug 9 15:16:29 CEST 2007


Hi Thomas,

The c/c framework has been broken already many times already; why
single out this one very minor example?  For example, there are many
instances where we have found it convenient to make SkyMapComposite
aware of its children in ways that seriously violate the strict
definition of c/c.  This is okay IMO, because strict c/c isn't quite
right for our use case.

If the recasting of a SkyComponent to a SkyMapComposite is troubling,
then we could simply change parent's type to SkyMapComposite:

LineListComponent::LineListComponent( SkyMapComposite *parent )
       : SkyComponent( parent ), LabelPosition( NoLabel ), Label(
QString() )
{
       m_skyLabeler = parent->skyLabeler();
}

Note this technically breaks c/c, but it's okay because we only need
LineListComponents that are direct children of SkyMapComposite.  If we
ever need LineListComponents deeper in the hierarchy, then we can
implement the dummy function as you suggest.

regards,
Jason

On 8/8/07, Thomas Kabelmann <thomas.kabelmann at gmx.de> wrote:
> Hi James,
>
> as I am enthused by your work, there is a small note I wanna do about this
> code fragment:
>
> LineListComponent::LineListComponent( SkyComponent *parent )
>         : SkyComponent( parent ), LabelPosition( NoLabel ), Label( QString() )
> {
>         m_skyLabeler = ((SkyMapComposite*) parent)->skyLabeler();
> }
>
> I find it very weird to cast from SkyComponent to a SkyMapComposite. As a
> compromise in the composite pattern the component class (interface) should
> know all methods, so that there is no cast needed. The component class could
> offer a default implementation which returns null and SkyMapComposite has the
> real implementation. So then we are really programming by interfaces and it
> makes the code more readable.
>
> I don't know, who put skyLabel() in the SkyMapComposite class. So don't be
> annoyed that I'm writing this to you :-) As I have no time until october to
> work on kstars, I would ask you, if you could clean up this mess in your
> branch too?
>
> Regards Thomas
> _______________________________________________
> Kstars-devel mailing list
> Kstars-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kstars-devel
>


More information about the Kstars-devel mailing list