Update Lesson 4 Task 3
This commit is contained in:
parent
92412bef42
commit
675692e965
10 changed files with 124 additions and 122 deletions
Lesson_4/Task_3
28
Lesson_4/Task_3/Classes/Administrator.cs
Normal file
28
Lesson_4/Task_3/Classes/Administrator.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using LiskovSubstitution.Interfaces;
|
||||
|
||||
namespace LiskovSubstitution.Classes
|
||||
{
|
||||
public class Administrator : User, IAdministrator
|
||||
{
|
||||
|
||||
public void WriteToFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Written to the file.");
|
||||
}
|
||||
|
||||
public void DeleteFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Deleted the file.");
|
||||
}
|
||||
|
||||
public void CopyFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Copied the file.");
|
||||
}
|
||||
|
||||
public void SaveToFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Saved to the file.");
|
||||
}
|
||||
}
|
||||
}
|
18
Lesson_4/Task_3/Classes/Owner.cs
Normal file
18
Lesson_4/Task_3/Classes/Owner.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using LiskovSubstitution.Interfaces;
|
||||
|
||||
namespace LiskovSubstitution.Classes
|
||||
{
|
||||
public class Owner : Administrator, IOwner
|
||||
{
|
||||
|
||||
public Guid CheckRole(Guid role)
|
||||
{
|
||||
return role;
|
||||
}
|
||||
|
||||
public Guid CheckUser(Guid user)
|
||||
{
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
28
Lesson_4/Task_3/Classes/User.cs
Normal file
28
Lesson_4/Task_3/Classes/User.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using LiskovSubstitution.Interfaces;
|
||||
|
||||
namespace LiskovSubstitution.Classes
|
||||
{
|
||||
public class User : IUser
|
||||
{
|
||||
|
||||
public string ReadFromFile(string filename)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void DownloadFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Downloaded the file.");
|
||||
}
|
||||
|
||||
public void GetDataFromFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Got data from the file.");
|
||||
}
|
||||
|
||||
public void CheckFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Checked the file.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LiskovSubstitution
|
||||
{
|
||||
public interface IWorkingWithFile
|
||||
{
|
||||
public string ReadFromFile(string filename);
|
||||
public void WriteToFile(string filename);
|
||||
public void DeleteFile(string filename);
|
||||
public void DownloadFile(string filename);
|
||||
public void CopyFile(string filename);
|
||||
public void GetDataFromFile(string filename);
|
||||
public void CheckFile(string filename);
|
||||
public void SaveToFile(string filename);
|
||||
public Guid CheckRole(Guid role);
|
||||
public Guid CheckUser(Guid user);
|
||||
}
|
||||
}
|
16
Lesson_4/Task_3/Interfaces/IAdministrator.cs
Normal file
16
Lesson_4/Task_3/Interfaces/IAdministrator.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LiskovSubstitution.Interfaces
|
||||
{
|
||||
public interface IAdministrator : IUser
|
||||
{
|
||||
public void WriteToFile(string filename);
|
||||
public void DeleteFile(string filename);
|
||||
public void CopyFile(string filename);
|
||||
public void SaveToFile(string filename);
|
||||
}
|
||||
}
|
14
Lesson_4/Task_3/Interfaces/IOwner.cs
Normal file
14
Lesson_4/Task_3/Interfaces/IOwner.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LiskovSubstitution.Interfaces
|
||||
{
|
||||
public interface IOwner : IAdministrator
|
||||
{
|
||||
public Guid CheckRole(Guid role);
|
||||
public Guid CheckUser(Guid user);
|
||||
}
|
||||
}
|
16
Lesson_4/Task_3/Interfaces/IUser.cs
Normal file
16
Lesson_4/Task_3/Interfaces/IUser.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LiskovSubstitution.Interfaces
|
||||
{
|
||||
public interface IUser
|
||||
{
|
||||
public string ReadFromFile(string filename);
|
||||
public void DownloadFile(string filename);
|
||||
public void GetDataFromFile(string filename);
|
||||
public void CheckFile(string filename);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using LiskovSubstitution;
|
||||
using LiskovSubstitution.Classes;
|
||||
|
||||
(new User()).SaveToFile("test");
|
||||
// CS1061
|
||||
// (new User()).SaveToFile("test");
|
||||
|
||||
(new Administrator()).SaveToFile("test");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
namespace LiskovSubstitution
|
||||
{
|
||||
public class User : IWorkingWithFile
|
||||
{
|
||||
public virtual Guid Role { get; } = new Guid("a65d9c1d-b8a9-4f4f-be9b-ab03856f33f4");
|
||||
|
||||
public string ReadFromFile(string filename)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void WriteToFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Access denied.");
|
||||
}
|
||||
|
||||
public void DeleteFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Access denied.");
|
||||
}
|
||||
|
||||
public void DownloadFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Downloaded the file.");
|
||||
}
|
||||
|
||||
public void CopyFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Access denied.");
|
||||
}
|
||||
|
||||
public void GetDataFromFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Got data from the file.");
|
||||
}
|
||||
|
||||
public void CheckFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Checked the file.");
|
||||
}
|
||||
|
||||
public void SaveToFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Access denied.");
|
||||
}
|
||||
|
||||
public Guid CheckRole(Guid role)
|
||||
{
|
||||
return new Guid("00000000-0000-0000-0000-000000000000");
|
||||
}
|
||||
|
||||
public Guid CheckUser(Guid user)
|
||||
{
|
||||
return new Guid("00000000-0000-0000-0000-000000000000");
|
||||
}
|
||||
}
|
||||
|
||||
public class Administrator : User
|
||||
{
|
||||
public override Guid Role { get; } = new Guid("c1cfcc4a-e49e-4585-9ccb-265c35321b11");
|
||||
|
||||
public new void WriteToFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Written to the file.");
|
||||
}
|
||||
|
||||
public new void DeleteFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Deleted the file.");
|
||||
}
|
||||
|
||||
public new void CopyFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Copied the file.");
|
||||
}
|
||||
|
||||
public new void SaveToFile(string filename)
|
||||
{
|
||||
Console.WriteLine("Saved to the file.");
|
||||
}
|
||||
}
|
||||
|
||||
public class Owner : User
|
||||
{
|
||||
public override Guid Role { get; } = new Guid("a157c9cf-c996-46d7-9905-4cd1319a451d");
|
||||
|
||||
public new Guid CheckRole(Guid role)
|
||||
{
|
||||
return role;
|
||||
}
|
||||
|
||||
public new Guid CheckUser(Guid user)
|
||||
{
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue