On Thursday, 21 September 2023 at 18:19:47 UTC, Imperatorn wrote:
On Sunday, 17 September 2023 at 15:05:59 UTC, Vitaliy Fadeev wrote:
Hi!
I want to change a method ```Draw``` on a custom object when the ```MouseIn``` event occurs. This is known as "Change State" of the object: ```Init``` -> ```Hovered```.

[...]

Interesting, but why would you want to do it that way? 😳

Q & A.
You can check the logic.

How to increase the battery life of a smartphone?

Reducing operations.

How to change the state of a button widget, for example, on mouseover?

By changing the pointer to the Draw method.

In addition to Draw, the widget has a Sense method. How to replace all pointers to methods at once?

Replace the pointer with a class.

(It's like a change of state! Exactly Turing's State Machine.)

The object fields are the same. Behavior changes.

The contents of the fields remain in memory. Only the pointer to the method table changes.

Of course, this requires care and forethought.

Perhaps the risks of changing class can be reduced by performing additional checks.

Changing class is a convenient tool. I want to use it.

Reply via email to