Add Factory Design pattern
Factory design patter is added Some print line for place holder Need to imiplement Private instances
This commit is contained in:
parent
bcfedfec60
commit
96224ef96f
26
src/Archive/.vscode/launch.json
vendored
Normal file
26
src/Archive/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/app/bin/Debug/net6.0/app.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/app",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
||||
42
src/Archive/.vscode/tasks.json
vendored
Normal file
42
src/Archive/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/app/app.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/app/app.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/app/app.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
51
src/Archive/app/ArchiveController.cs
Normal file
51
src/Archive/app/ArchiveController.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
|
||||
namespace app
|
||||
{
|
||||
class ArchiveController{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string dsName = "SQL";
|
||||
string cmd = "";
|
||||
Console.WriteLine("Hello World!");
|
||||
|
||||
//SQLConnection myconnection = new SQLConnection();
|
||||
|
||||
// Creating a DataSource Factory to make Data sources
|
||||
DataSourceFactory dsFactory = new DataSourceFactory();
|
||||
|
||||
// Creating a SQL data source objects to gain access to the SQL database
|
||||
IDataSource dataSource = dsFactory.getDataSource("SQL");
|
||||
|
||||
// Read from the database
|
||||
dataSource.ReadData("a");
|
||||
|
||||
// Write to the database
|
||||
dataSource.WriteData("Insert newName");
|
||||
|
||||
// Update the datasource
|
||||
dataSource.UpdateData();
|
||||
|
||||
// Delete from the datasource
|
||||
dataSource.DeleteData();
|
||||
|
||||
Console.WriteLine("-----------------");
|
||||
// Creating a Data Source for text files
|
||||
IDataSource txtSource = dsFactory.getDataSource("txt");
|
||||
|
||||
// Read from the database
|
||||
txtSource.ReadData("a");
|
||||
|
||||
// Write to the database
|
||||
txtSource.WriteData("a");
|
||||
|
||||
// Update the datasource
|
||||
txtSource.UpdateData();
|
||||
|
||||
// Delete from the datasource
|
||||
txtSource.DeleteData();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
src/Archive/app/DataSourceFactory.cs
Normal file
18
src/Archive/app/DataSourceFactory.cs
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
class DataSourceFactory{
|
||||
public IDataSource getDataSource(string name){
|
||||
|
||||
if (name == "SQL"){
|
||||
return new SQLSource();
|
||||
}
|
||||
else if (String.Equals(name, "TXT", StringComparison.OrdinalIgnoreCase)){
|
||||
return new TxtSource();
|
||||
}
|
||||
else if(name == "XML"){
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
6
src/Archive/app/Factory.cs
Normal file
6
src/Archive/app/Factory.cs
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
abstract class Factory{
|
||||
|
||||
//Method to make a datasource object
|
||||
public abstract IDataSource getDataSource(string name);
|
||||
}
|
||||
15
src/Archive/app/IDataSource.cs
Normal file
15
src/Archive/app/IDataSource.cs
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
interface IDataSource{
|
||||
|
||||
// Method for reading data, return 0 for sucessful operation
|
||||
int ReadData(string cmd);
|
||||
|
||||
// Method for Writing data to a data source
|
||||
int WriteData(string cmd);
|
||||
|
||||
//Method for deleteing data from a data source, 0 for successful
|
||||
int DeleteData();
|
||||
|
||||
// Method for updating data from a data source, 0 for sucessful
|
||||
int UpdateData();
|
||||
}
|
||||
0
src/Archive/app/NewFactory.cs
Normal file
0
src/Archive/app/NewFactory.cs
Normal file
41
src/Archive/app/SQLSource.cs
Normal file
41
src/Archive/app/SQLSource.cs
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
class SQLSource : IDataSource{
|
||||
//private SQLConnection conn;
|
||||
|
||||
// public SQLSource(){
|
||||
// conn = new SQLConnection("usernamePasword");
|
||||
// }
|
||||
|
||||
public int ReadData(string cmd){
|
||||
try{
|
||||
// conn.open();
|
||||
// conn.Execute();
|
||||
Console.WriteLine("Access a SQL database");
|
||||
Console.WriteLine("Select * from archive");
|
||||
|
||||
// while (myReader)
|
||||
// Print to console
|
||||
// conn.close();
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e){
|
||||
Console.WriteLine(e.Message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public int WriteData(string cmd){
|
||||
Console.WriteLine("Writing data to a SQL database");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int DeleteData() {
|
||||
Console.WriteLine("Deleting data from a SQL database");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int UpdateData() {
|
||||
Console.WriteLine("Update data to a SQL database");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
29
src/Archive/app/TxtSource.cs
Normal file
29
src/Archive/app/TxtSource.cs
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
class TxtSource : IDataSource{
|
||||
private string fileName;
|
||||
public int ReadData(string a){
|
||||
try{
|
||||
Console.WriteLine("Access a text file");
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e){
|
||||
Console.WriteLine(e.Message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public int WriteData(string cmd){
|
||||
Console.WriteLine("Writing data to a text file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int DeleteData() {
|
||||
Console.WriteLine("Deleting data from a text file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int UpdateData() {
|
||||
Console.WriteLine("Update data to a text file");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
10
src/Archive/app/app.csproj
Normal file
10
src/Archive/app/app.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user