On Tuesday, 17 May 2022 at 00:10:55 UTC, Alain De Vos wrote:
Let's say a shape is ,a circle with a radius ,or a square with
a rectangular size.
I want to pass shapes to functions, eg to draw them on the
screen,
draw(myshape) or myshape.draw();
But how do i implement best shapes ?
You could al
On Tuesday, 17 May 2022 at 09:30:12 UTC, forkit wrote:
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote:
In you OOP example, I am curious why you chose Shape to be an
interface, rather than a base class.
You can inherit from multiple interfaces, but only from one base
class.
So
On 5/17/22 02:30, forkit wrote:
> On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote:
>>
>
> In you OOP example, I am curious why you chose Shape to be an interface,
> rather than a base class.
I always have the same question. :) interface feels lighterweight, so it
is an arbitrary decis
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote:
In you OOP example, I am curious why you chose Shape to be an
interface, rather than a base class.
On Tuesday, 17 May 2022 at 05:08:30 UTC, matheus wrote:
In D there would be a better way to do such thing?
Nothing really specific to D, but for one or two properties, you
might just add them as function parameters with default values:
```d
void draw(float scale = 1.0f);
```
If you have
On Tuesday, 17 May 2022 at 00:10:55 UTC, Alain De Vos wrote:
Let's say a shape is ,a circle with a radius ,or a square with
a rectangular size.
I want to pass shapes to functions, eg to draw them on the
screen,
draw(myshape) or myshape.draw();
But how do i implement best shapes ?
In addition
On 5/16/22 22:08, matheus wrote:
> interface Shape {
>void draw();
>void draw(float scale);
> }
Interfaces can have 'final' functions:
interface Shape {
void draw(float scale);
final void draw() {
draw(1);
}
}
Obviously, for that to work, now Circle.draw() etc. required to r
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote:
...
2) If you want to have a shape hierarchy, then you can start by
defining its interface and implement that interface by concrete
shape types. Drawing is ordinarily handled by member functions:
...
Hi Ali, I'm not the author but I
On 5/16/22 17:10, Alain De Vos wrote:
Let's say a shape is ,a circle with a radius ,or a square with a
rectangular size.
I want to pass shapes to functions, eg to draw them on the screen,
draw(myshape) or myshape.draw();
But how do i implement best shapes ?
There are many ways of achieving thi