Skip to content

Instantly share code, notes, and snippets.

Created September 6, 2013 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6463033 to your computer and use it in GitHub Desktop.
Save anonymous/6463033 to your computer and use it in GitHub Desktop.
private static LeaderboardName getLeaderboardName(
Kind kind, LeaderboardKind lbKind
) {
var kg = kind as Kind.Global;
if (kg != null)
return new LeaderboardName(
string.Format("lb_{0}", leaderboardKindToString(lbKind)), lbKind
);
var kw = kind as Kind.World;
if (kw != null)
return new LeaderboardName(
string.Format("lb_w{0}_{1}", kw.world, leaderboardKindToString(lbKind)),
lbKind
);
var kl = kind as Kind.Level;
if (kl != null)
return new LeaderboardName(
string.Format(
"lb_w{0}_l{1}{2}_{3}", kl.world, kl.level, kl.bonus ? "b" : "",
leaderboardKindToString(lbKind)
), lbKind
);
throw new Exception("Unknown kind " + kind);
}
@golergka
Copy link

Once again, very strange code, clearly not in C#-way.

So, you want to get leaderboard name from some object that is of class Kind. But why the hell do you create a separate static method for that? A clear and pretty simple objected-oriented approach would be to create an abstract method in Kind and to define it in it's children.

Are there any downfalls to this traditional OOP way of doing things that I don't see?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment