Hi All,
Learning; Please bear with me. Scenario: 1. Class>>User. InstVars: #(this that other userStatus userMeta) 2. Class>>UserManager (singleton). Instvars: users (RcIdentityBag: users) When User is instantiated all its' instVars are populated correctly. Nested objects as well. To insert the User into the UserManager singleton instVar I created an add: method on the instance side of UserManager to pass the User to the UserManager as per: --- add: aUser users add: aUser --- This works and I am able to created my database of users. The difficulty I am having is that when I want to query the UserManager db with something like: --- RcIdentityBag(users) select: [ :each | each name := 'somename' ] --- It seems that currently the only I know how to do this is to create a select: method in UserManager simply to pass the desired search string into the UserManager class such that I can use the Collection Classes api to do the actual work, as per: --- Pardon the not so smalltalky code --- UserManager>>select: aString | resultSet | resultSet := users select: [ :each | each name := aString ]. ^resultSet --- I believe I read somewhere that in order to avoid this clunkiness that I could refer to the users collection in UserManager via a symbol and access the api of the identitySet directly. Something like: --- UserManager class>>current UserGlobals at: #FOO put users. ... --- But when I do this I am unable to do something like: --- #FOO add: user --- Do to doesNotUndestand exceptions. Finally Questions: 1. Am I totally off the mark with the use of smalltalk symbols? 2. Must I create the API in the managing class to perform the specific functions I need from the collection API with respect to querying the collection? 3. Is there a smalltalk way of doing this properly that I missed (reading all the docs I can find in random order based of info I need - probably missing the finer points)? Any nudge in the correct direction would be greatly appreciated. Thanks! |
Not sure if it’s just a typo, but it appears you’re trying to use assignment ( := ) rather than comparison ( = ) so shouldn’t this be: select: [ :each | each name = 'somename' ]
This isn’t really necessary - it’s totally up to your application design. The singleton will work fine.
It all looks good, apart from the select block. Cheers |
In reply to this post by ian
Also if you add #FOO to UserGlobals you should be able to reference it like:
FOO add: user ie. without the symbol hash (#)
|
Free forum by Nabble | Edit this page |