Last active
September 12, 2015 04:45
-
-
Save ralfw/a0c95975badddbd1b54b to your computer and use it in GitHub Desktop.
ppoop solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace ppoop | |
{ | |
// source: http://www.csis.pace.edu/~bergin/patterns/ppoop.html | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
var osName = Get_operating_system_name (); | |
var osCategory = Categorize_operating_system (osName); | |
var msg = Qualify_operating_system (osCategory); | |
Inform_user (msg); | |
} | |
static string Get_operating_system_name() { | |
return System.Environment.OSVersion.VersionString; | |
} | |
enum OSCategories { | |
Unix, | |
Windows, | |
Unknown | |
} | |
static OSCategories Categorize_operating_system(string osName) { | |
if (osName.StartsWith("SunOS") || osName.StartsWith("Linux") || osName.StartsWith("Unix")) | |
{ | |
return OSCategories.Unix; | |
} | |
else if (osName.StartsWith("Windows NT") || osName.StartsWith("Windows 95")) | |
{ | |
return OSCategories.Windows; | |
} | |
else | |
{ | |
return OSCategories.Unknown; | |
} | |
} | |
static Dictionary<OSCategories,string> OSQualifications = | |
new Dictionary<OSCategories, string>{ | |
{OSCategories.Unix, "This is a UNIX box and therefore good."}, | |
{OSCategories.Windows, "This is a Windows box and therefore bad."}, | |
{OSCategories.Unknown, "This is not a box."} | |
}; | |
static string Qualify_operating_system(OSCategories osCategory) { | |
return OSQualifications [osCategory]; | |
} | |
static void Inform_user(string message) { | |
Console.WriteLine (message); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: http://www.csis.pace.edu/~bergin/patterns/ppoop.html | |
module Environment = | |
let get_operating_system_name = | |
System.Environment.OSVersion.VersionString; | |
let inform_user msg = | |
printfn "%s" msg | |
module Assessment = | |
type OSCategories = Unix | Windows | Unknown | |
let categorize_operating_system (name:string) = | |
if name.StartsWith("SunOS") || name.StartsWith("Linux") || name.StartsWith("Unix") | |
then Unix | |
else if name.StartsWith("Windows NT") || name.StartsWith("Windows 95") | |
then Windows | |
else Unknown | |
let qualify_operating_system = function | |
Unix -> "This is a UNIX box and therefore good." | |
| Windows -> "This is a Windows box and therefore bad." | |
| Unknown -> "This is not a box." | |
[<EntryPoint>] | |
let main _ = | |
Environment.get_operating_system_name | |
|> Assessment.categorize_operating_system | |
|> Assessment.qualify_operating_system | |
|> Environment.inform_user | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment