Does idiomatic way to code in go encourage oop practices


(Siddhanta Rath) #1

I know, go is all about type and values. There are no class and inheritance for good.Recently, In production, I have implemented a feature using factory and strategy patterns(In a oops way)
Just wanted to know, have I over engineered or am i abusing the idiomatic go practices ?


(J Ohn Stuart) #2

Less than other more oop centric languages, but it does encourage oop practices. Polymorphism and inheritance seem to be backed by the language the same as in C++ or Java.

Encapsulation and abstraction are the 2 traits that look like they’re not directly enforced. However, I am pleasantly surprised to read about pipelines and concurrency patterns - they do force developers to actively use encapsulation and abstraction - although in a somewhat different way.


(Siddhanta Rath) #3

is it okay to use all the oops design patterns in go like a factory pattern to create instance of structs ?


(J Ohn Stuart) #4

Sure, I do not see why not.

However, make sure you use multiple goroutines to split your work between multiple processors - this is the main advantage of go.