Fwd: Re: How can I make this more OOP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Re: How can I make this more OOP

Pharo Smalltalk Users mailing list



-------- 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 [hidden email]
Aan: Noury Bouraqadi [hidden email]


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



Reply | Threaded
Open this post in threaded view
|

Re: How can I make this more OOP

Noury Bouraqadi-2
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 <[hidden email]> 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 [hidden email]
Aan: Noury Bouraqadi [hidden email]


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