Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor how Add() / Remove() are customised #36

Open
jchesterpivotal opened this issue Jun 5, 2019 · 0 comments
Open

Refactor how Add() / Remove() are customised #36

jchesterpivotal opened this issue Jun 5, 2019 · 0 comments
Labels
enhancement New feature or request simulation/stocks

Comments

@jchesterpivotal
Copy link
Contributor

In Skenario the Stock is a key object; different parts of the simulation are expected to mostly locate their logic in Add() and Remove().

In the current implementation this is achieve with a subclassing-like structure. For example, ReplicasDesired:

type ReplicasDesiredStock interface {
	simulator.ThroughStock
}

which then uses an internal delegate stock to handle some tasks:

func (rds *replicasDesiredStock) Name() simulator.StockName {
	return rds.delegate.Name()
}

func (rds *replicasDesiredStock) KindStocked() simulator.EntityKind {
	return rds.delegate.KindStocked()
}

func (rds *replicasDesiredStock) Count() uint64 {
	return rds.delegate.Count()
}

func (rds *replicasDesiredStock) EntitiesInStock() []*simulator.Entity {
	return rds.delegate.EntitiesInStock()
}

But where Add() and Remove() are fairly extensive, as they describe the actual logic of interest.

This sub-ish class-ish approach works well enough and it's a relatively consistent pattern across the codebase. However it's a bit tedious to write tests over and over to ensure the delegate is properly wired.

It might be easier to change this relationship into a factory function of some kind. Pass in the Add() and Remove() function bodies and get back a wired-up Stock. This would reduce some of the boilerplate and repetitive testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request simulation/stocks
Projects
None yet
Development

No branches or pull requests

1 participant