{"id":307,"date":"2009-11-29T23:40:29","date_gmt":"2009-11-29T22:40:29","guid":{"rendered":"http:\/\/www.gennard.net\/blog\/?p=307"},"modified":"2009-11-29T23:40:29","modified_gmt":"2009-11-29T22:40:29","slug":"design-patterns-and-cobol","status":"publish","type":"post","link":"http:\/\/www.gennard.net\/blog\/2009\/11\/design-patterns-and-cobol\/","title":{"rendered":"Design Patterns and COBOL"},"content":{"rendered":"<p>As part of my working life I happy to say I use COBOL and for better or worse it is here to stay.  With this in mind it annoys me I here\/see saying things such as <\/p>\n<blockquote><p>COBOL is a old language that naturally prohibits you from using modern design patterns.<\/p><\/blockquote>\n<p>rubbish I say&#8230; COBOL can be used in good ways and bad ways.<\/p>\n<p>I will try and show you that COBOL can be used in a good way&#8230; lets take the &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Singleton_pattern\">Singleton pattern<\/a>&#8220;, as the first example.<\/p>\n<p>First.. lets start off my creating a singleton class in csharp&#8230; so here it is: <\/p>\n<p><code lang=\"csharp\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\nusing System.Collections;<\/p>\n<p>public sealed class MySingleton {<br \/>\n\tprivate static readonly Hashtable sharedHashtable = new Hashtable();<\/p>\n<p>\t\/\/ Explicit static constructor to tell C# compiler<br \/>\n\t\/\/ not to mark type as beforefieldinit<br \/>\n\tstatic MySingleton() {<br \/>\n\t}<\/p>\n<p>\tprivate MySingleton() {<br \/>\n\t}<\/p>\n<p>\tpublic static Hashtable Singleton {<br \/>\n\t\tget {<br \/>\n\t\t\treturn sharedHashtable;<br \/>\n\t\t}<br \/>\n\t}<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Not too shabby.. but lets see what we can do in COBOL&#8230; <\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n      $set ilusing\"System.Collections\"<br \/>\n       class-id.  \"MySingleton\".<\/p>\n<p>       01 shared-hashtable  type \"Hashtable\"<br \/>\n            static property as \"Singleton\" with no set.<\/p>\n<p>       method-id. \"New\" static.<br \/>\n          set shared-hashtable to new type \"Hashtable\"<br \/>\n       end method \"New\".<br \/>\n<\/code><\/p>\n<p>What&#8230; COBOL is smaller&#8230; that can&#8217;t be true&#8230; sorry but it is&#8230;<\/p>\n<p>To complete the example&#8230; lets use it&#8230;<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n      *> Add two items to the single hashtable<br \/>\n         invoke type \"MySingleton\"::\"Singleton\"::<br \/>\n                \"Add\"(\"01234567\",\"Ian\")<\/p>\n<p>         invoke type \"MySingleton\"::\"Singleton\"::<br \/>\n                \"Add\"(\"987654321\",\"Stephen\")<\/p>\n<p>      *> Now get one of the items of the singleton<br \/>\n         display \"Account 01234567 - Contains: \"<br \/>\n             type \"MySingleton\"::\"Singleton\"::\"Item\"(\"01234567\")<br \/>\n<\/code><\/p>\n<p>And I am sure some people&#8230; will say sure&#8230; this is really true&#8230; it is&#8230; here is it running.. <\/p>\n<p><code lang=\"text\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\nc:temp> cobol MySingleton.cbl ilgen(sub);<br \/>\nc:temp> cobol UseSingleton.cbl ilgen ilref\"MySingleton.dll\";<br \/>\nc:temp> UseSingleton.exe<br \/>\nAccount 01234567 - Contains: Ian<br \/>\nc:temp> csc MySingleton.cs \/target:library<br \/>\nc:temp> UseSingleton.exe<br \/>\nAccount 01234567 - Contains: Ian<br \/>\n<\/code><\/p>\n<p>Now it seems to me that COBOL is being under rated&#8230; perhaps someone should shout about it! \ud83d\ude42 <\/p>\n<p>[ad#Google Adsense-3]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of my working life I happy to say I use COBOL and for better or worse it is here to stay. With this in mind it annoys me I here\/see saying things such as COBOL is a old &hellip; <a href=\"http:\/\/www.gennard.net\/blog\/2009\/11\/design-patterns-and-cobol\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,32],"tags":[209,87,171],"_links":{"self":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/307"}],"collection":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":0,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}