diff --git a/factory-class-example.cs b/factory-class-example.cs new file mode 100644 index 0000000..04e0149 --- /dev/null +++ b/factory-class-example.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace factory1 +{ + class Program + { + abstract class Position + { + public abstract string Title { get; } + } + + class Clerk : Position + { + public override string Title + { + get { return "Clerk"; } + } + } + + class Manager : Position + { + public override string Title + { + get { return "Manager"; } + } + } + + class Programmer : Position + { + public override string Title + { + get { return "Programmer"; } + } + } + + static class Factory + { + public static Position Get(int id) + { + switch (id) + { + case 0: + return new Manager(); + case 1: + case 2: + return new Clerk(); + default: + return new Programmer(); + } + } + } + + static void Main(string[] args) + { + for (int i = 0; i < 3; i++) + { + Position position = Factory.Get(i); + Console.WriteLine("Where id = {0}, position = {1}", i, position.Title); + } + } + } +} diff --git a/factory-class-exercise.cs b/factory-class-exercise.cs new file mode 100644 index 0000000..049a548 --- /dev/null +++ b/factory-class-exercise.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace factory2 +{ + interface IButton { } + + class WinButton : IButton { } + class OSXButton : IButton { } + + interface IGUIFactory + { + IButton CreateButton(); + } + + class WinFactory : IGUIFactory + { + + public IButton CreateButton() + { + return new WinButton(); + } + } + + class OSXFactory : IGUIFactory + { + + public IButton CreateButton() + { + return new OSXButton(); + } + } + + class Program + { + public static void App(IGUIFactory factory) + { + IButton btn = factory.CreateButton(); + } + static void Main(string[] args) + { + App(new OSXFactory()); + } + } +} diff --git a/uml.cs b/uml.cs new file mode 100644 index 0000000..1a47f15 --- /dev/null +++ b/uml.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace uml +{ + class Person + { + public string Name; + public int Age; + } + + class Professor : Person + { + public string Degree; + } + + class Student : Person + { + public string level; + } + + class Classroom + { + public Professor Professor; + + public List students = new List(); + } + + class Program + { + static void Main(string[] args) + { + Professor p = new Professor() { Age = 27, Name = "Nathan Adams", Degree = "Bachelor of science" }; + Classroom oo70245 = new Classroom() { Professor = p }; + oo70245.students.Add(new Student() { Name = "Microsoft Bob", Age = 18, level = "Freshman" }); + oo70245.students.Add(new Student() { Name = "Microsoft Bob2", Age = 20, level = "Sophmore" }); + } + } +}