Created
February 29, 2024 04:15
-
-
Save theepicsnail/5a7ac7d26108428405eafb0d06b96ace to your computer and use it in GitHub Desktop.
thing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class V1CurrentPlayerData | |
{ | |
// a bunch of random bullshit has to happen for these to get the right values when you run the app | |
public static string username; | |
public static int points; | |
} | |
public class V1ExampleUsage | |
{ | |
public void Update() | |
{ | |
Debug.Log(V1CurrentPlayerData.username); | |
} | |
} | |
// Okay so we refactor into using an interface | |
public interface V2CurrentPlayerData | |
{ | |
// Define an interface with that structure instead of the impl everyone reads/writes to. | |
// I don't really know csharpisms lol so here i'll just lay out all the functions. | |
public int getPoints(); | |
public void setPoints(int p); | |
public string getUsername(); | |
public void setUsername(string s); | |
// Here's your static instance where all the data goes! It could be anywhere tbh. Here for convenience. | |
public static V2CurrentPlayerData Instance = new V2CurrentPlayerDataProd(); | |
} | |
public class V2CurrentPlayerDataProd : V2CurrentPlayerData | |
{ | |
// Normal stuff here | |
private int points; | |
private string username; | |
public int getPoints() { return points; } | |
public void setPoints(int p) { points = p; } | |
public string getUsername() { return username; } | |
public void setUsername(string u) { username = u;} | |
} | |
public class V2CurrentPlayerDataTestingThings : V2CurrentPlayerData | |
{ | |
// This impl is for you to skip all the prod shit and just skip to the values you want to try out your code with. | |
public int getPoints() { return 12345123; } | |
public void setPoints(int p) { /* shrug */ } | |
public string getUsername() { return null; /* Let's see what happens if username is null! */ } | |
public void setUsername(string u) { /*shrug*/} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment