Skip to content

Commit 8848c1d

Browse files
committedApr 16, 2017
Add MVC pattern.
1 parent 80dbefd commit 8848c1d

9 files changed

+209
-2
lines changed
 

‎Do factory - .Net Design Pattern.sln

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26403.3
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Visitor", "Visitor\Visitor.csproj", "{5EA68B2D-F6FF-4490-BBCF-7E7797036077}"
77
EndProject
@@ -55,6 +55,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "State", "State\State.csproj
5555
EndProject
5656
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Template Method", "Template Method\Template Method.csproj", "{659E048D-1F8D-466D-B262-080E8BE5F103}"
5757
EndProject
58+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVC", "MVC\MVC.csproj", "{B4BE9923-6A62-40AB-AFDC-AD292AFEBE69}"
59+
EndProject
5860
Global
5961
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6062
Debug|Any CPU = Debug|Any CPU
@@ -153,6 +155,10 @@ Global
153155
{659E048D-1F8D-466D-B262-080E8BE5F103}.Debug|Any CPU.Build.0 = Debug|Any CPU
154156
{659E048D-1F8D-466D-B262-080E8BE5F103}.Release|Any CPU.ActiveCfg = Release|Any CPU
155157
{659E048D-1F8D-466D-B262-080E8BE5F103}.Release|Any CPU.Build.0 = Release|Any CPU
158+
{B4BE9923-6A62-40AB-AFDC-AD292AFEBE69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
159+
{B4BE9923-6A62-40AB-AFDC-AD292AFEBE69}.Debug|Any CPU.Build.0 = Debug|Any CPU
160+
{B4BE9923-6A62-40AB-AFDC-AD292AFEBE69}.Release|Any CPU.ActiveCfg = Release|Any CPU
161+
{B4BE9923-6A62-40AB-AFDC-AD292AFEBE69}.Release|Any CPU.Build.0 = Release|Any CPU
156162
EndGlobalSection
157163
GlobalSection(SolutionProperties) = preSolution
158164
HideSolutionNode = FALSE
@@ -181,5 +187,6 @@ Global
181187
{1F2CAAE0-4BFF-424F-82F4-BE4DBF23BD30} = {5210D741-A652-4DDE-94E1-ACE571B51A35}
182188
{21F4D812-3118-4BB7-A1D1-85BFDA20AA34} = {5210D741-A652-4DDE-94E1-ACE571B51A35}
183189
{659E048D-1F8D-466D-B262-080E8BE5F103} = {5210D741-A652-4DDE-94E1-ACE571B51A35}
190+
{B4BE9923-6A62-40AB-AFDC-AD292AFEBE69} = {4A46F10E-8B98-46DE-91A3-D83C858A0387}
184191
EndGlobalSection
185192
EndGlobal

‎MVC/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
5+
</startup>
6+
</configuration>

‎MVC/MVC.csproj

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{B4BE9923-6A62-40AB-AFDC-AD292AFEBE69}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>MVC</RootNamespace>
10+
<AssemblyName>MVC</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Program.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
<Compile Include="Student.cs" />
48+
<Compile Include="StudentController.cs" />
49+
<Compile Include="StudentView.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="App.config" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Content Include="mvc_pattern_uml_diagram.jpg" />
56+
</ItemGroup>
57+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
58+
</Project>

‎MVC/Program.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
6+
namespace MVC
7+
{
8+
/// <summary>
9+
/// MVCPattern Demo
10+
/// </summary>
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
//fetch student record based on his roll no from the database
16+
Student model = retriveStudentFromDatabase();
17+
18+
//Create a view : to write student details on console
19+
StudentView view = new StudentView();
20+
21+
StudentController controller = new StudentController(model, view);
22+
23+
controller.UpdateView();
24+
25+
//update model data
26+
controller.SetStudentName("John");
27+
28+
controller.UpdateView();
29+
}
30+
31+
private static Student retriveStudentFromDatabase() => new Student("Robert", 10);
32+
}
33+
}
34+
35+
// source: https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm

‎MVC/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("MVC")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("MVC")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("b4be9923-6a62-40ab-afdc-ad292afebe69")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

‎MVC/Student.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace MVC
2+
{
3+
class Student
4+
{
5+
public string Name { get; set; }
6+
public int RollNo { get; set; }
7+
8+
public Student(string name, int rollNo)
9+
{
10+
Name = name;
11+
RollNo = rollNo;
12+
}
13+
}
14+
}

‎MVC/StudentController.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace MVC
2+
{
3+
class StudentController
4+
{
5+
// model
6+
private Student _studentModel;
7+
8+
// TODO: change to event pattern.
9+
private StudentView _studentView;
10+
11+
public StudentController(Student studentModel, StudentView studentView)
12+
{
13+
_studentModel = studentModel;
14+
_studentView = studentView;
15+
}
16+
17+
public void SetStudentName(string name)
18+
{
19+
_studentModel.Name = name;
20+
}
21+
22+
// not in real app this is supposed to recive a ID which the student will be identified by
23+
public string GetStudentName() => _studentModel.Name;
24+
25+
public void SetStudentRollNo(int rollNo)
26+
{
27+
_studentModel.RollNo = rollNo;
28+
}
29+
30+
public int GetStudentRollNo() => _studentModel.RollNo;
31+
32+
public void UpdateView()
33+
{
34+
_studentView.PrintStudnetDetails(_studentModel.Name, _studentModel.RollNo);
35+
}
36+
}
37+
}

‎MVC/StudentView.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace MVC
4+
{
5+
class StudentView
6+
{
7+
public void PrintStudnetDetails(string name, int rollNo)
8+
{
9+
Console.WriteLine("Student: ");
10+
Console.WriteLine("Name: {0}", name);
11+
Console.WriteLine("Roll No: {0}", rollNo);
12+
}
13+
}
14+
}

‎MVC/mvc_pattern_uml_diagram.jpg

22.3 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.