-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hasan ALTAN
committed
Dec 17, 2020
1 parent
6c6cd36
commit 1bb9352
Showing
29 changed files
with
571 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
SolidPrinciples/Lab_1_SingleResponsiblePrinciple/BadExample/BadEmployeeProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using SolidPrinciples.Lab_1_SingleResponsiblePrincible.Model; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_1_SingleResponsiblePrincible.BadExample | ||
{ | ||
public class BadEmployeeProcess | ||
{ | ||
public void InsertEmployee(Employee newEmployee) // That is insert of Employee our 1 work on the Theorical example. | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
try | ||
{ | ||
#region 1.Process=>First Job Adding New Worker | ||
sb.Append(newEmployee.Id); | ||
sb.AppendLine(); | ||
sb.Append(newEmployee.FirstName); | ||
sb.AppendLine(); | ||
sb.Append(newEmployee.LastName); | ||
sb.AppendLine(); | ||
sb.Append(newEmployee.HireDate); | ||
File.WriteAllText(@"C:\SolidEmployeeData.txt", sb.ToString()); | ||
#endregion | ||
|
||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
#region 2.Process=>When the failure of this first process | ||
sb = new StringBuilder(); | ||
sb.Append("Failure Date:"); | ||
sb.Append(DateTime.Now.ToString()); | ||
sb.AppendLine(); | ||
sb.Append("Failure Message:"); | ||
sb.Append(ex.Message); | ||
File.WriteAllText(@"C:\SolidLog.txt", ToString()); | ||
System.Windows.Forms.MessageBox.Show("Opps..Warning Failured"); | ||
#endregion | ||
|
||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
SolidPrinciples/Lab_1_SingleResponsiblePrinciple/GoodExample/GoodEmployeeProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using SolidPrinciples.Lab_1_SingleResponsiblePrincible.Model; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_1_SingleResponsiblePrincible.GoodExample | ||
{ | ||
public class GoodEmployeeProcess:GoodLogerProcess | ||
{ | ||
GoodEmployeeProcess logger; | ||
public GoodEmployeeProcess() | ||
{ | ||
logger = new GoodEmployeeProcess(); | ||
} | ||
|
||
string log; | ||
public bool InsertEmployee(Employee newEmployee) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
try | ||
{ | ||
sb.Append(newEmployee.Id); | ||
sb.AppendLine(); | ||
sb.Append(newEmployee.FirstName); | ||
sb.AppendLine(); | ||
sb.Append(newEmployee.LastName); | ||
|
||
log = logger.BuildLog(sb.ToString()); | ||
logger.LogFile(@"C:\SolidLog.txt", log); | ||
|
||
log = logger.BuildLog($"Employee insert successfull => {newEmployee.Id}"); | ||
logger.LogFile(@"C:\SolidLog.txt", log); | ||
|
||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
log = logger.BuildLog("Failure Message:" + ex.Message); | ||
logger.LogFile(@"C:\SolidLog.txt", log); | ||
|
||
return false; | ||
|
||
} | ||
} | ||
|
||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
SolidPrinciples/Lab_1_SingleResponsiblePrinciple/GoodExample/GoodLogerProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_1_SingleResponsiblePrincible.GoodExample | ||
{ | ||
public class GoodLogerProcess | ||
{ | ||
public void LogFile(string filePath,string log) | ||
{ | ||
File.WriteAllText(filePath, log); | ||
|
||
} | ||
public string BuildLog(string information) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
sb.Append("Date:"); | ||
sb.Append(DateTime.Now.ToString()); | ||
sb.AppendLine(); | ||
sb.Append("Information:").Append(information); | ||
return sb.ToString(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
SolidPrinciples/Lab_1_SingleResponsiblePrinciple/Model/Employee.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_1_SingleResponsiblePrincible.Model | ||
{ | ||
public class Employee | ||
{ | ||
public int Id { get; set; } | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
public DateTime HireDate { get; set; } | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
SolidPrinciples/Lab_1_SingleResponsiblePrinciple/Theorical.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Single Responsibility Principle | ||
|
||
This principle support that " One class should have just a one job" and " One class should have just a oneresponsibility."Most of Developer,ın the scenerio that wants to add new property or new behaviour,they provide same class.That is totally wrong approach in terms of SRP.When it is applied these codes becomes long and complex and it effects time management when repair. | ||
|
||
For example, | ||
Registration of new worker; | ||
*New worker notifications, | ||
*Send to notification of new worker to Manager, | ||
|
||
In this situation,we can all of them just a one class.But if we do that,we will face with SRP.Why do we prevent to failure of SRP? | ||
-First of all codes that is writen , may change to spaghetti codes.And it will be problem on the repair time or when we want to change something it will effect our time in terms of finding. | ||
How can we obey this principle? | ||
-In the example,2 different job should be done in the 2 different class. | ||
|
||
|
35 changes: 35 additions & 0 deletions
35
SolidPrinciples/Lab_2_OpenClosedPrinciple/BadExample/CoffeeType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_2_OpenClosedPrinciple.BadExample | ||
{ | ||
public enum CoffeeType | ||
{ | ||
Latte,Espresso,Machiato | ||
} | ||
public class BadCoffee | ||
{ | ||
public double GetTotalPrice(double amount,CoffeeType coffeeType) | ||
{ | ||
double totalPrice = 0; | ||
if (coffeeType==CoffeeType.Espresso) | ||
{ | ||
totalPrice += amount * 4.50; | ||
|
||
} | ||
else if (coffeeType==CoffeeType.Latte) | ||
{ | ||
totalPrice += amount * 4.50; | ||
|
||
} | ||
else if (coffeeType==CoffeeType.Machiato) | ||
{ | ||
totalPrice += amount * 6.75; | ||
} | ||
return totalPrice; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
SolidPrinciples/Lab_2_OpenClosedPrinciple/GoodExample/Abstract/GoodCar.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_2_OpenClosedPrinciple.GoodExample | ||
{ | ||
public abstract class GoodCar | ||
{ | ||
public abstract double GetTotalPrice(double amount); | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SolidPrinciples/Lab_2_OpenClosedPrinciple/GoodExample/Concrete/Door.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_2_OpenClosedPrinciple.GoodExample.Concrete | ||
{ | ||
public class Door : GoodCar | ||
{ | ||
public override double GetTotalPrice(double amount) | ||
{ | ||
return amount*5.21; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SolidPrinciples/Lab_2_OpenClosedPrinciple/GoodExample/Concrete/Gear.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_2_OpenClosedPrinciple.GoodExample.Concrete | ||
{ | ||
public class Gear:GoodCar | ||
{ | ||
public override double GetTotalPrice(double amount) | ||
{ | ||
return amount*68.75; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SolidPrinciples/Lab_2_OpenClosedPrinciple/GoodExample/Concrete/Whell.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_2_OpenClosedPrinciple.GoodExample.Concrete | ||
{ | ||
public class Whell : GoodCar | ||
{ | ||
public override double GetTotalPrice(double amount) | ||
{ | ||
return amount * 7.99; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Open/Closed Principle | ||
|
||
Entities should close to changeable but it can be develop or extend.All classes that we want to create our other demand is creating extendable class.Also OOP support to extend every classes.But on this extend process creating classes should be design as a class doesnt need to modification.Basically,we don't change method and behaviour of this class but we can change class. | ||
|
||
In the example; | ||
While a developer wants to update for library and framework ,that demands of the others for this changed codes developer easily reach to his codes and these codes can be changeable,by this way, he doesn't need to write all again. | ||
Attention point is while we are adding a new special property for any method we doesn't change our methods that we created before. | ||
|
||
At this Lab,think a basic coffeshop app.In this app we should have coffee class and species of coffe class and also we should get enum class that to use coffee and species class informations.For every coffee species that we need to add,we are going to enum.At this point,as a result of extending,we have to change for two classes and then we are opposite of OCP.But if we create an abstract class that contained a method and then we should use override.By this way,we don't chane anyhing on the classes. | ||
|
25 changes: 25 additions & 0 deletions
25
SolidPrinciples/Lab_3_LiskovsSubstituionPinciple/BadExample/BadAreaCalculator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.BadExample | ||
{ | ||
public class BadAreaCalculator | ||
{ | ||
public static double CalculateArea(BadRectangle badRectangle) | ||
{ | ||
return badRectangle.Height * badRectangle.Width; | ||
|
||
} | ||
|
||
public static double CalculateAre(BadSquare badSquare) | ||
{ | ||
|
||
// | ||
return badSquare.Height * badSquare * Withd; | ||
|
||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
SolidPrinciples/Lab_3_LiskovsSubstituionPinciple/BadExample/BadRectangle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.BadExample | ||
{ | ||
|
||
//This is parent class | ||
public class BadRectangle | ||
{ | ||
|
||
//on the bad example,parent class is BadRectangle class and members of BadRactengle assigned virtual | ||
public virtual int Height { get; set; } | ||
public virtual int Width { get; set; } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
SolidPrinciples/Lab_3_LiskovsSubstituionPinciple/BadExample/BadSquare.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.BadExample | ||
{ | ||
public class BadSquare:BadRectangle | ||
{ | ||
|
||
// | ||
int _height; | ||
int _widht; | ||
|
||
public override int Height { get =>_height | ||
; set => _height = value; } | ||
|
||
public override int Width { get => _widht | ||
; set => _widht = value; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
SolidPrinciples/Lab_3_LiskovsSubstituionPinciple/GoodExample/Abstract/Shape.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.GoodExample.Abstract | ||
{ | ||
public abstract class Shape | ||
{ | ||
//For this principle ,avoid of parent class aim failure, | ||
|
||
public int Id { get; set; } | ||
public int Edge { get; set; } | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SolidPrinciples/Lab_3_LiskovsSubstituionPinciple/GoodExample/Concrete/Rectangle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.GoodExample.Abstract; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.GoodExample.Concrete | ||
{ | ||
public class Rectangle:Shape | ||
{ | ||
public int width { get; set; } | ||
public double RectangleArea() { return width * Edge; } | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
SolidPrinciples/Lab_3_LiskovsSubstituionPinciple/GoodExample/Concrete/Square.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.GoodExample.Abstract; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolidPrinciples.Lab_3_Liskov_s_Substituion_Pinciple.GoodExample.Concrete | ||
{ | ||
public class Square:Shape | ||
{ | ||
public double SquareArea() | ||
{ | ||
return Edge * Edge; | ||
} | ||
} | ||
} |
Oops, something went wrong.