"Best fit" to avoid reuse of object instances in a collection
        Posted  
        
            by 
                Simon
            
        on Programmers
        
        See other posts from Programmers
        
            or by Simon
        
        
        
        Published on 2012-10-29T08:55:45Z
        Indexed on 
            2012/10/29
            11:17 UTC
        
        
        Read the original article
        Hit count: 305
        
design-patterns
|object-oriented
Imagine I have a collection of object instances which represent activities for a user to undertake. Dependent on user attributes, I have to randomly select instances to present activities to the user.
For some users, I need to present more activities to them than there are available activities in which case, I want to use the following algorithm.
If all available activities have already been presented to the user, then re-select a "used" activity, selecting the earliest presented activity ordered by frequency of use. In other words, try to reduce repetition and where repetition is unavoidable, use the instances which have been repeated less often and were presented furthest back in time.
Before I go on to code that algorithm, I wondered if there is some existing pattern I can re-use?
[EDIT] "Furthest back in time" is not relevant as I will pass the algorithm an ordered collection of used instances where the first entry is the first presented.
© Programmers or respective owner