-------- Doorgestuurd bericht -------- Onderwerp: Re: [Pharo-users] How can I make this more OOP Datum: Sun, 13 Sep 2020 16:43:59 +0200 Van: Roelof Wobben <r.wobben@home.nl> Aan: Noury Bouraqadi <bouraqadi@gmail.com>
Hello, Noury,
Thanks for letting me see this but I wonder if it is good practice to place my own methods on the Object and UndefinedObject ?
Roelof
Op 13-9-2020 om 14:51 schreef Noury Bouraqadi:
Hi Roelof,
Polymorphism is the answer.
Object >> flattenInto: result
result nextPut: anObject
UndefinedObject >> flattenInto: result
^self
Collection >> flattenInto: result
self do: [ :item | item flattenInto: result ]
flatten: anObject
^ (OrderedCollection streamContents: [ :stream | anObject flattenInto: stream ]) asArray
Noury
Your own methods can be added to any class. Just ensure they are introduced as class extensions attached to your project's package.
Use the checkbox at the bottom of the system browser.
On 13 Sep 2020, at 16:44, Roelof Wobben via Pharo-users pharo-users@lists.pharo.org wrote:
-------- Doorgestuurd bericht --------
Onderwerp: Re: [Pharo-users] How can I make this more OOP
Datum: Sun, 13 Sep 2020 16:43:59 +0200
Van: Roelof Wobben r.wobben@home.nl mailto:r.wobben@home.nl
Aan: Noury Bouraqadi bouraqadi@gmail.com mailto:bouraqadi@gmail.com
Hello, Noury,
Thanks for letting me see this but I wonder if it is good practice to place my own methods on the Object and UndefinedObject ?
Roelof
Op 13-9-2020 om 14:51 schreef Noury Bouraqadi:
Hi Roelof,
Polymorphism is the answer.
Object >> flattenInto: result
result nextPut: anObject
UndefinedObject >> flattenInto: result
^self
Collection >> flattenInto: result
self do: [ :item | item flattenInto: result ]
flatten: anObject
^ (OrderedCollection streamContents: [ :stream | anObject flattenInto: stream ]) asArray
Noury