oo-70-245-1

oo-70-245-1 Commit Details


Date:2015-10-12 20:11:18 (9 years 2 months ago)
Author:Natalie Adams
Branch:master
Commit:f7e69ab6d2f63017f8f79e2aadc28318a95986fb
Parents: 3dd8646d2dd448d044e121507cf6e28cb9c62703
Message:adding examples in class

Changes:

File differences

factory-class-example.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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);
}
}
}
}
factory-class-exercise.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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());
}
}
}
uml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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<Student> students = new List<Student>();
}
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" });
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.06057s using 14 queries.