[OOP][C#] Refactoring a large C# class RRS feed

  • Question

  • I have noticed that my classes tend to be larger/longer compared to code I tend to read online. The code below is intended as an example, but I am more interested in the way to think about and how to approach the problem.

    As you will see the class handles many roles and I would love to learn on how to refactor it into other classes and examples, if possible, on practical solutions. Links to books/guides on how to solve this problem would be great.

    public static class Backend {
        //These classes are the equivalent classes of a cloud database tables
        //Using them to map the tables to objects in my app
        public class User{}
        public class Place{}
        public class SubPriority{}
        public class Question{}
        public class Parent{}
        public class Response{}
        public class SubParent{}
        //initialize the local and cloud databases
        public static async void init();
        //Add place to local database
        public static string AddPlace(string name, string buildingType)
        //Retrieve places from local database
        public static List<Place> RetrievePlaces()
        //Delete a place from local database
        public static bool DeletePlace(string placeID)
        public static string AddSubPriority(String name)
        public static List<SubPriority> RetrieveSubPriorities()
        public static bool DeleteSubPriority(string placeID, int ID)
        //Sync local db with cloud
        public static async Task<bool> SyncWithCloud()
        //Download SubParents from the cloud
        public static async Task<List<SubParent>> DownloadSubParents()
        //Retrieve SubParents from local
        public static List<SubParent> RetrieveSubParents(int parentid)
        //Similar methods for parents and questions
        //Handling login
        public static async Task<bool> Login(string userName, string pass)
        static async Task<bool> LoginOnline(string userName, string pass)
        static bool LoginOffline(string userName, string pass)
        //Check for internet connectivity
        static async Task<bool> isConnectedToInternet()
        static bool InternetAvailable()

    Saturday, August 15, 2015 12:32 PM


All replies