<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel>
	  <title>Ask MetaFilter questions tagged with designpattern</title>
      <link>http://ask.metafilter.com/tags/designpattern</link>
      <description>Questions tagged with 'designpattern' at Ask MetaFilter.</description>
	  <pubDate>Wed, 16 Apr 2008 10:19:40 -0800</pubDate> <lastBuildDate>Wed, 16 Apr 2008 10:19:40 -0800</lastBuildDate>

      <language>en-us</language>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <ttl>60</ttl>	  
	<item>
	<title>In an OOP world, what&apos;s the best way to handle a lot of sequential code?</title>
	<link>http://ask.metafilter.com/88972/In%2Dan%2DOOP%2Dworld%2Dwhats%2Dthe%2Dbest%2Dway%2Dto%2Dhandle%2Da%2Dlot%2Dof%2Dsequential%2Dcode</link>	
	<description>Design-pattern (programming) question. I&apos;m working on a huge app (many thousand lines of code), and one of the most complex parts of it is the initialization logic. There&apos;s a ton of code that needs to run sequentially and only once.&lt;br&gt;
&lt;br&gt;
Currently, I&apos;m handling all of this with singletons, but I wonder if there&apos;s a better way.&lt;br&gt;
&lt;br&gt;
Here&apos;s the basic framework now (in pseudocode).&lt;br&gt;
&lt;br&gt;
MainInit.getInstance().init();&lt;br&gt;
&lt;br&gt;
/* inside MainInit&apos;s init() method... */&lt;br&gt;
&lt;br&gt;
DataManager.getInstance().init();&lt;br&gt;
CommandManager.getInstance().init();&lt;br&gt;
GraphicsManager.getInstance().init();&lt;br&gt;
... etc ... //maybe 40 more calls like this&lt;br&gt;
&lt;br&gt;
This seems pretty straightforward and easy to maintain. I don&apos;t have any real problems with it. But it&apos;s sort of off-the-top-of-my-head. I&apos;ve never worked on an app that needs so much initializing before. &lt;br&gt;
&lt;br&gt;
Since it&apos;s not really about objects -- it&apos;s just about tons of code running in sequential order -- I&apos;m not sure of the best, tried and true method of breaking it up into manageable chunks. And I can&apos;t find much about it in my Design Pattern books.&lt;br&gt;
&lt;br&gt;
I&apos;m cool with non design-pattern solutions, too. I know patterns aren&apos;t for everything. I just need a really good way of organizing this sort of code.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.88972</guid>
	<pubDate>Wed, 16 Apr 2008 10:19:40 -0800</pubDate>
	<category>application</category>
	<category>code</category>
	<category>design</category>
	<category>designpattern</category>
	<category>init</category>
	<category>initialization</category>
	<category>organization</category>
	<category>organizing</category>
	<category>pattern</category>
	<category>patterns</category>
	<category>programmer</category>
	<category>singleton</category>
	<category>singletons</category>
	<dc:creator>grumblebee</dc:creator>
	</item>
	<item>
	<title>Design Pattern Quandry</title>
	<link>http://ask.metafilter.com/86673/Design%2DPattern%2DQuandry</link>	
	<description>Programming/design pattern question.  Being self-taught, I&apos;ve discovered a number of times I&apos;ve labored over the solution to a problem only to discover a more elegant, standard design pattern already addresses the problem.  I&apos;m sort of hoping this is the case here.

What I want to do is provide a way for users to arbitrarily combine given numbers to generate meaningful-to-them numbers and have the means of doing this combining persist.  For example, the application I have in mind stores counting statistics in baseball by player and date.  As a user of this application, I&apos;d like to be able to combine these stats in various ways that are more or less arbitrary from the application&apos;s POV.  Many common formulas can be pre-programmed, i.e. &lt;code&gt;OBP = (Hits + Walks + HBP ) / (AB + Sac + Walks + HBP)&lt;/code&gt;.  However, many may not be so easily anticipated, i.e. &lt;code&gt;Quality Start = if( GS &amp;amp;&amp;amp; (IP &amp;gt;= 6) &amp;amp;&amp;amp; (ER &amp;lt;= 3) ) then return 1&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;
Instead of having to create a new class (oh, I&apos;m using Java here) every time a user develops a new stat they&apos;d like generated/displayed/scored in fantasy baseball, I&apos;d like to develop a way to generate these classes/objects via the ui and then re-use them in subsequent user sessions.  I can see how to do this in the UI using drag/drop or drop-down menus, but I don&apos;t know how to model this on the back end.&lt;br&gt;
&lt;br&gt;
My present model suggests a class &lt;code&gt;StatLine&lt;/code&gt; that is essentially a &lt;code&gt;Collection&lt;/code&gt; of an arbitrary number of objects that implement a &lt;code&gt;Stat&lt;/code&gt; interface.  This interface describes methods like set/get value, get title/label, and get/set formula in addition to some other bookkeeping kinds of things like how to sort for scoring (ascending vs. descending).  How to represent, store, and retrieve arbitrary formulas is the part that has me spinning in circles.  It would seem that this is an ideal situation to use some combination of a properties file and reflection but the means have not yet come to me.&lt;br&gt;
&lt;br&gt;
Something along the lines of:&lt;br&gt;
&lt;code&gt;public class AVG implements Stat {&lt;br&gt;
&lt;br&gt;
public AVG( Stat Hits, Stat AB ) {&lt;br&gt;
...&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
.... all kinds of getters and setters....&lt;br&gt;
&lt;br&gt;
public Double getValue() {&lt;br&gt;
...read some property that represents the formula and feed that formula to some kind of engine that returns the computed value...&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
It could be that I should drop the idea of making unique classes that implement the &lt;code&gt;Stat&lt;/code&gt;s interface for each statistic generated.  Instead one could monkey together an engine that turned a string in to a calculation that is stored as a field in a &lt;code&gt;Stat&lt;/code&gt;s object.  It just doesn&apos;t feel right though.&lt;br&gt;
&lt;br&gt;
If you have run in to a pattern like this how did you solve it?  What, if any, name does this design pattern have?  What, if any, resources would you recommend for asking this question to a more specific audience?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.86673</guid>
	<pubDate>Thu, 20 Mar 2008 14:30:17 -0800</pubDate>
	<category>designpattern</category>
	<category>java</category>
	<category>pattern</category>
	<category>software</category>
	<dc:creator>Fezboy!</dc:creator>
	</item>
	
	</channel>
</rss>

