[Gambas-user] OO design problem?

Fabien Bodard gambas.fr at ...626...
Sun Aug 28 22:20:46 CEST 2016


It's not unnecessary in fact. Imagine if a children not implement the
property... then it's the property in the parent that is readed.


Another way is to not declare the property in the parent and use an
object type to walk the children.


Dosometing(hChild as Myclass)

dim hObj as Object = hChild

try hObj.DoSomethingElse()

end



I use MyClass type in param to ensure to have a MyClass type passed.

Then i use an Object Var that allow a call to unknow symbole and a try
for manage the error if the symbol is not implemented.

By this way the property can be not implemented in the parent without
generating error. I use this to manage ReportControl... For exemple
ReportLabel have a Text property that is not implemented in
ReportControl.



2016-08-28 20:37 GMT+02:00 Jussi Lahtinen <jussi.lahtinen at ...626...>:
> I have class which is meant only to function as parent to other classes.
> This class have empty properties and methods, which are there only to be
> over-driven in the children classes. If I remove them I get error that the
> properties are not declared, and if I remove the properties from the parent
> I cannot use them when the object is passed as the parent.
>
> So, is it be possible to do this without declaring empty _read functions
> and _write subs?
>
> I want to be able to pass the objects like this:
>
> Sub DoSomething(hAnyChildrenOfThisClass As ThisClass)
>
>   x = hAnyChildrenOfThisClass.SomethingElse()
>   ...
>
> End
>
>
> Now the "SomethingElse" must be declared in "ThisClass" so that the
> children can have it and over-drive it with actual content.
> So, I'm looking a way to write only this:
>
> In ThisClass:
>
> Property SomethingElse  As Interger
>
>
> Instead of all this, which make a lot of unnecessary mess:
>
> Property SomethingElse  As Interger
>
>
> Private Function SomethingElse_Read() As Integer
>
>   Return 0
>
> End
>
> Private Sub SomethingElse_Write(Value As Integer)
>
> End
>
>
> It's very likely that I have missed something and I have some crucial
> design problem. So all suggestions are welcome!
> Thanks!
>
>
> Jussi
> ------------------------------------------------------------------------------
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



-- 
Fabien Bodard




More information about the User mailing list