java - Conditional in a method that way more than often has already been satisified -


although question not specific java explanation targeted java helpful. problem have done several programs , have manipulated pre-existing games , find there checks 99% or more of time doesn't have person trying do.

lets have achievement system , have earn achievement dance. people dance time , have earned achievement long ago , have been dancing hours on end. each time dance there going check see if have done achievement if haven't can given achievement. how can around checking once not apply person anymore?

you can use event bus. dance method create event pushed event bus. initially, there part of code going listen dance event. once listener triggered dance event, unregister listener of dance event.

edit: similar idea without using eventbus.

interface danceeventhandler {     void handle(danceevent e); } 

let there user object each user.

class user {     ....     danceeventhandler danceeventhandler; } 

initially can use implementation dance event.

class defaultdanceeventhandler {     void handle(danceevent e) {         //give achievement user     } } 

once user have achievement, replace danceeventhandler in user different implementation.

class afterachievementdanceeventhandler {     void handle(danceevent e) {         //do nothing     } } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -