IntegerCount subclass: #DivisorCount
	instanceVariableNames: 'oddCount evenCount '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Counts'


DivisorCount methodsFor: 'initialize'

initialize
	"initialize the DivisorCount object"

	oddCount := IntegerCount new.	"Create the two slave counts"
	evenCount := IntegerCount new.
	ButtonLessViewContainer new openOn: oddCount labeled: 'Odd'. "attach the slave counts to views"
	ButtonLessViewContainer new openOn: evenCount labeled: 'Even'.
	super initialize.	"call our inherited initialize method"

DivisorCount methodsFor: 'counting'

decrement
	"decrement ourself and dependencies"

	super decrement.	"call our inherited decrement method"
	"determine whether the new value is odd or even, and send appropriate messages to slave windows"
	value even ifTrue: [ evenCount decrement ] ifFalse: [ oddCount decrement ] .

increment
	"increment ourself and dependencies"

	super increment.		"call our inherited increment method"
	"determine whether the new value is odd or even, and send appropriate messages to slave windows"
	value even ifTrue: [ evenCount increment ] ifFalse: [ oddCount increment ] .

reset
	"reset ourself and dependencies"

	super reset.			"use our inherited reset method"
	oddCount reset.		"tell the odd slave model to reset itself"
	evenCount reset.	"tell the even slave model to reset itself"

DivisorCount class methodsFor: 'initialize'

new
	"create a new DivisorCount and attach it to a CountViewContainer"

	| me |	"the new DivisorCount we'll create"

	me := super new.		"use our inherited new method"
	CountViewContainer new openOn: me labeled: 'Master'.
	^me.				"return the new DivisorCount"