-
-
Save azhuox/be139a402252b286d0f90336e1244366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package encapsulationexample | |
// SimpleCounter - a simple counter. | |
type SimpleCounter struct { | |
counter int | |
} | |
// NewCounter - creates a new counter instance. | |
func NewCounter() *SimpleCounter { | |
return &SimpleCounter{ | |
counter: 0, | |
} | |
} | |
// N - return current counter's value. | |
func (c *SimpleCounter) N() int { return c.counter } | |
// Increment - increases the counter by 1 without considering the risk of race condition. | |
func (c *SimpleCounter) Increment() { c.counter++ } | |
// Reset - resets the counter. | |
func (c *SimpleCounter) Reset() { c.counter = 0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment