New topic: How to break up an overbloated class that is tightly coupled
<http://forums.realsoftware.com/viewtopic.php?t=31426> Page 1 of 1 [ 1 post ] Previous topic | Next topic Author Message guykuo Post subject: How to break up an overbloated class that is tightly coupledPosted: Sat Dec 05, 2009 5:30 pm Joined: Mon Apr 02, 2007 5:51 pm Posts: 210 This is a basic design question I'm dealing with as I refactor a large project to break up large classes into more digestible pieces. My basic strategy has been to create a new new "worker" sub-classes implement groups of related methods that bloated the original class. My problem is with passing tightly coupled, complex properties to those worker classes efficiently, reliably and syntactically cleanly. I've run into what seems a hole in the RB language..... A "MyObject" class originally has a very large collection of methods including related ones that that I want to be handled by subclasses Code: OriginalClassZ has properties prop1, prop1, prop2 (which are pretty large, complex properties like arrays and pictures and other objects) methods groupableMethod1 directly accesses prop1, prop2, prop3 groupableMethod2 directly accesses prop1, prop2, prop3 groupableMethod3 directly accesses prop1, prop2, prop3 groupableMethod4 directly accesses prop1, prop2, prop3 someOtherMethodsUnrelatedA to above but also alters prop1, prop2, prop3 someOtherMethodsUnrelatedB to above but also alters prop1, prop2, prop3 someOtherMethodsUnrelatedC to above but also alters prop1, prop2, prop3 I change OriginalClassZ and create a new "worker" class to implement the logically related methods (i.e.. a series of "find" methods in a findWorker class) Code: streamlinedZClass has properties prop1, prop1, prop2 workerZ an instance of workerClassZ that upon instantiation must have its prop1, prop1, prop2 linked ByRef to point at streamlinedZClass's properties in its constructor i.e.. constructor(byRef newProp1, byRef newProp2, byRef newProp3) followed by prop1 = newProp1 etc. methods someOtherMethodsUnrelatedA to above but also alters prop1, prop2, prop3 someOtherMethodsUnrelatedB to above but also alters prop1, prop2, prop3 someOtherMethodsUnrelatedC to above but also alters prop1, prop2, prop3 where workerZ now houses the related methods I'm grouping functionality together in a new class Code: workerClassZ properties prop1, prop2, prop3 which MUST be kept ByRef to the parent's prop1, prop2, prop3 methods groupableMethod1 uses its prop1, prop2, prop3 which should be byRef groupableMethod2 uses its prop1, prop2, prop3 which should be byRef groupableMethod3 uses its prop1, prop2, prop3 which should be byRef groupableMethod4 uses its prop1, prop1, prop2 which should be byRef This works and breaks up the originalClassZ into more readily digested worker classes that carry out logically related methods for the new streamlinedZClass BUT I'm very concerned that this arrangement is prone to breakage if a streamlinedZClass method or other worker class alters a property in a manner that could break linkage for the workers. For instance, prop1 = newpicture (w, h, 32) would make prop1 be a new picture. I think that would break the original byRef relationship for the workers so I'm having each worker update its linkages when a property is reacreated. You see why I"m worrying this will lead to accidental code breakage in future rewrites. I thought about shared properties, but that won't work since I have more than one instance of the original object and shared prop1, prop2, and prop3 would be shared among all members of the class instead of being specific to instances. or perhaps a dataClass that gets passed with each worker.method call, but that would incur overhead. Since breaking out logically related methods is such an important part of making classes readable and we often have tightly coupled methods, I'm thinking there must a be an elegant way to do this that I'm missing. How do you best solve this in RB when breaking up your big classes? Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 1 post ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
