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: don't design interfaces, discover them. #110

Closed

Conversation

muktihari
Copy link
Member

"Don't design with interfaces, discover them" - Rob Pike

Interfaces should be created by the consumer instead of the producer. The consumer, in this case service/service.go (Service{}), are the one who decides which methods are needed to carry the operation. We as software engineer should discover it this way, not by designing interfaces. The producer, in this case fit, gpx, and tcx, only responsible to satisfy the interface.

The interface named Service in activity/service.go is removed, the name of Service interface is renamed to DecodeEncoder as it only needs to do two things, to decode and to encode. This also eliminates the ambiguity surrounding the name 'Service'.

@muktihari muktihari added the enhancement New feature or request label Sep 2, 2024
@muktihari muktihari self-assigned this Sep 2, 2024
func NewService(preproc *activity.Preprocessor) activity.Service {
return &service{preprocessor: preproc}
// NewDecodeEncoder creates new GPX decode-encoder.
func NewDecodeEncoder(preproc *activity.Preprocessor) *DecodeEncoder {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the constructor return concrete type rather than interface for flexibility

fs := fit.NewService(preproc)
gs := gpx.NewService(preproc)
ts := tcx.NewService(preproc)
fit := fit.NewDecodeEncoder(preproc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, This local variable name may cause confusion when maintain in the future

@muktihari muktihari closed this Sep 6, 2024
@muktihari muktihari deleted the refactor/discover-interfaces branch September 6, 2024 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants