tag:blogger.com,1999:blog-4016790357096156934.post6444359706981373670..comments2023-12-16T03:44:42.484-06:00Comments on RichieSam's Adventures in Code-ville: Improving the 'Object' class (including renaming it) and using classes for ResultActionsRichieSamshttp://www.blogger.com/profile/11068267631031438940noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-4016790357096156934.post-37471587007827099642013-07-03T16:24:24.471-05:002013-07-03T16:24:24.471-05:00While I agree that the giant if-then is really rea...While I agree that the giant if-then is really really ugly, I feel that the chain of responsibility approach would have too much data hiding and too much class inter-connectivity. Let me explain my thought process.<br /><br />Each class has a static factory method. In it it does this:<br />if (line is the right type) {<br /> return constructor;<br />} else {<br /> return ;<br />}<br /><br />However, doing this will hide the order of the chain, plus requires the individual classes to know about each other.<br /><br />Perhaps I missing something?RichieSamshttps://www.blogger.com/profile/11068267631031438940noreply@blogger.comtag:blogger.com,1999:blog-4016790357096156934.post-7833554642798839472013-07-03T15:24:06.229-05:002013-07-03T15:24:06.229-05:00Hi Richie,
great post about the evolution of your ...Hi Richie,<br />great post about the evolution of your design.<br />I can suggest you read a bit about the "chain of responsibility" design pattern (http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern) as it is applicable for your problem.<br />Instead of big if-then list that knows what each Action class can handle, let the Action classes tell you if they can handle the given line.<br />Then you just chain them together and let the chain find the first match that can handle.<br />You might have to change your decision to construct the action instance with all the data. I didn't think it through.<br />But the main point is that the information about what each Action class can handle is encapsulated in the class and not outside.Omer Morhttps://www.blogger.com/profile/05524751715995551821noreply@blogger.com