I'm pretty new with Go and then I searched a lot how to have a static class with static function/variables such as C# by example. But, I couldn't find anything which answered well about it. Maybe this question seems stupid, but I don't like either when I'm not sure or when I don't understand completely something.
Let say we have this code:
public class Program
{
public static string name = "Program tester.";
public enum Importance
{
None,
Trivial,
Regular,
Important,
Critical
};
public static void tester(Importance value)
{
// ... Test against known Importance values.
if (value == Importance.Trivial)
{
Console.WriteLine("Not true");
}
else if (value == Importance.Critical)
{
Console.WriteLine("True");
}
}
}
Golang is a C-like if I understand, so does it have some behavior like this one above, such as C++/C# languages? My code above can be achieved as C++/C# or the way to do it is to passing by a language as C (using the C modular programming way)?
There's no real way to get a static member of a struct like you would with a static member of a Java class, but you add metadata or a tag to a struct using StructTags:
https://medium.com/golangspec/tags-in-golang-3e5db0b8ef3e
What are the use(s) for tags in Go?
https://golang.org/pkg/reflect/#StructTag
typically we see them when creating a struct for use with unmarshaing JSON:
There is no inheritance in Go,
but you can do all OOP stuff in Golang way.
also see:
https://github.com/luciotato/golang-notes/blob/master/OOP.md https://www.goinggo.net/2013/07/object-oriented-programming-in-go.html
1: static var in C# class => global var in Golang package
2: enum in C# => new package with enum name and const type of enum elements
3: class in OOP => struct type
4: class methods => struct with receiver methods
5: C#/Java abstract methods(pure virtual functions in C++) => interface methods like io.Reader
6: public => first letter Upper case Name
7: private => first letter lower case name
8: namespace => package name
9: inheritance => embedded struct and embedded interface
10: Thread => Go routines
11: lock => sync.Mutex
...