Skip to content

Commit eb48ccc

Browse files
committed
Refactored code
1 parent 8888977 commit eb48ccc

15 files changed

+256
-309
lines changed

Chapter05/Components/Button.cs

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
using Chapter05.Contracts;
22

3-
namespace Chapter05.Components
3+
namespace Chapter05.Components;
4+
5+
public class Button(int id, string name, (double, double) position)
6+
: ButtonBase(id, name, position), IDrawable
47
{
5-
public class Button
6-
: ButtonBase, IDrawable
7-
{
8-
protected bool IsCorneredCurve { get; set; }
9-
public string Text { get; set; }
10-
public Button(int id, string name, (double, double) position)
11-
: base(id, name, position)
12-
{
13-
}
8+
protected bool IsCorneredCurve { get; set; }
9+
public string? Text { get; set; }
1410

15-
public void Draw()
16-
{
17-
Console.WriteLine("Button draw at {0}:{1}", Position.Item1, Position.Item2);
18-
}
19-
public override string ToString()
20-
{
21-
return $"{base.ToString()}|{Text}|{IsCorneredCurve}";
22-
}
11+
public void Draw()
12+
{
13+
Console.WriteLine("Button draw at {0}:{1}", Position.Item1, Position.Item2);
14+
}
15+
public override string ToString()
16+
{
17+
return $"{base.ToString()}|{Text}|{IsCorneredCurve}";
2318
}
2419
}

Chapter05/Components/ButtonBase.cs

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
namespace Chapter05.Components
1+
namespace Chapter05.Components;
2+
3+
/*
4+
Control sınıfından türeyen ButtonBase, Button türevli bileşenleri ifade eder.
5+
Tüm Button'lar için ortak olabilecek bazı özellikleri veya metotları içerebilir.
6+
*/
7+
public abstract class ButtonBase(int id, string name, (double, double) position)
8+
: Control(id, name, position)
29
{
310
/*
4-
Control sınıfından türeyen ButtonBase, Button türevli bileşenleri ifade eder.
5-
Tüm Button'lar için ortak olabilecek bazı özellikleri veya metotları içerebilir.
11+
Aslında arka plan ve ön plan rengi ve hatta yazının büyüklüğü, türü, yatık olması vs
12+
gibi unsular FontStyle gibi farklı bir sınıfın özellikleri olabilir.
613
*/
7-
public abstract class ButtonBase
8-
: Control
9-
{
10-
/*
11-
Aslında arka plan ve ön plan rengi ve hatta yazının büyüklüğü, türü, yatık olması vs
12-
gibi unsular FontStyle gibi farklı bir sınıfın özellikleri olabilir.
13-
*/
14-
public string BackgroundColor { get; set; }
15-
public string ForegroundColor { get; set; }
16-
protected ButtonBase(int id, string name, (double, double) position)
17-
: base(id, name, position)
18-
{
19-
}
20-
}
14+
public string? BackgroundColor { get; set; }
15+
public string? ForegroundColor { get; set; }
2116
}

Chapter05/Components/CheckBox.cs

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-

2-
using Chapter05.Contracts;
1+
using Chapter05.Contracts;
32

4-
namespace Chapter05.Components
3+
namespace Chapter05.Components;
4+
5+
public class CheckBox(int id, string name, (double, double) position)
6+
: Control(id, name, position), IDrawable
57
{
6-
public class CheckBox
7-
: Control, IDrawable
8+
public string? Text { get; set; }
9+
public bool IsChecked { get; set; }
10+
11+
public void Draw()
12+
{
13+
Console.WriteLine("CheckBox draw at {0}:{1}", Position.Item1, Position.Item2);
14+
}
15+
public override string ToString()
816
{
9-
public string Text { get; set; }
10-
public bool IsChecked { get; set; }
11-
public CheckBox(int id, string name, (double, double) position) : base(id, name, position)
12-
{
13-
}
14-
public void Draw()
15-
{
16-
Console.WriteLine("CheckBox draw at {0}:{1}", Position.Item1, Position.Item2);
17-
}
18-
public override string ToString()
19-
{
20-
return $"{base.ToString()}|{Text}|{IsChecked}";
21-
}
17+
return $"{base.ToString()}|{Text}|{IsChecked}";
2218
}
2319
}

Chapter05/Components/Control.cs

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
namespace Chapter05.Components
1+
namespace Chapter05.Components;
2+
3+
/*
4+
Tasarımımıza göre ekrana çizilebilen tüm bileşenleri tarifleyen nesnedir.
5+
*/
6+
public abstract class Control(int id, string name, (double, double) position)
27
{
3-
/*
4-
Tasarımımıza göre ekrana çizilebilen tüm bileşenleri tarifleyen nesnedir.
5-
*/
6-
public abstract class Control
8+
public int Id { get; set; } = id;
9+
protected string? Name { get; set; } = name;
10+
protected (double, double) Position { get; set; } = position;
11+
12+
public override string ToString()
713
{
8-
public int Id { get; set; }
9-
protected string Name { get; set; }
10-
protected (double, double) Position { get; set; }
11-
protected Control(int id, string name, (double, double) position)
12-
{
13-
Id = id;
14-
Name = name;
15-
Position = position;
16-
}
17-
public override string ToString()
18-
{
19-
return $"{Id}|{this.GetType().Name}|{Name}|{Position}";
20-
}
14+
return $"{Id}|{this.GetType().Name}|{Name}|{Position}";
2115
}
2216
}

Chapter05/Components/DbConnector.cs

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
namespace Chapter05.Components
1+
namespace Chapter05.Components;
2+
3+
/*
4+
DbConnector sınıfının en büyük özelliği bir Control olması ama Draw metodunu içermemesidir.
5+
Tasarımımıza göre her kontrol Container nesne içerisinde çizilebilir olacak diye bir kural yoktur.
6+
*/
7+
public class DbConnector(int id, string name, (double, double) position)
8+
: Control(id, name, position)
29
{
3-
/*
4-
DbConnector sınıfının en büyük özelliği bir Control olması ama Draw metodunu içermemesidir.
5-
Tasarımımıza göre her kontrol Container nesne içerisinde çizilebilir olacak diye bir kural yoktur.
6-
*/
7-
public class DbConnector
8-
: Control
9-
{
10-
public string ConnectionString { get; set; }
10+
public string? ConnectionString { get; set; }
1111

12-
public DbConnector(int id, string name, (double, double) position)
13-
: base(id, name, position)
14-
{
15-
}
16-
public override string ToString()
17-
{
18-
return $"{base.ToString()}|{ConnectionString}";
19-
}
12+
public override string ToString()
13+
{
14+
return $"{base.ToString()}|{ConnectionString}";
2015
}
2116
}

Chapter05/Components/GridBox.cs

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
using Chapter05.Contracts;
22

3-
namespace Chapter05.Components
3+
namespace Chapter05.Components;
4+
5+
internal class GridBox(int id, string name, (double, double) position)
6+
: Control(id, name, position), IDrawable
47
{
5-
internal class GridBox
6-
: Control, IDrawable
8+
public int RowCount { get; set; }
9+
public int ColumnCount { get; set; }
10+
11+
public void Draw()
12+
{
13+
Console.WriteLine("GridBox draw at {0}:{1}", Position.Item1, Position.Item2);
14+
}
15+
public override string ToString()
716
{
8-
public int RowCount { get; set; }
9-
public int ColumnCount { get; set; }
10-
public GridBox(int id, string name, (double, double) position)
11-
: base(id, name, position)
12-
{
13-
}
14-
public void Draw()
15-
{
16-
Console.WriteLine("GridBox draw at {0}:{1}", Position.Item1, Position.Item2);
17-
}
18-
public override string ToString()
19-
{
20-
return $"{base.ToString()}|{RowCount}|{ColumnCount}";
21-
}
17+
return $"{base.ToString()}|{RowCount}|{ColumnCount}";
2218
}
2319
}

Chapter05/Components/Label.cs

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
using Chapter05.Contracts;
22

3-
namespace Chapter05.Components
4-
{
5-
public class Label
6-
: Control, IDrawable
7-
{
8-
public string Text { get; set; }
3+
namespace Chapter05.Components;
94

10-
public Label(int id, string name, (double, double) position)
11-
: base(id, name, position)
12-
{
13-
}
5+
public class Label(int id, string name, (double, double) position)
6+
: Control(id, name, position), IDrawable
7+
{
8+
public string Text { get; set; }
149

15-
public void Draw()
16-
{
17-
Console.WriteLine("Label draw at {0}:{1}", Position.Item1, Position.Item2);
18-
}
19-
public override string ToString()
20-
{
21-
return $"{base.ToString()}|{Text}";
22-
}
10+
public void Draw()
11+
{
12+
Console.WriteLine("Label draw at {0}:{1}", Position.Item1, Position.Item2);
13+
}
14+
public override string ToString()
15+
{
16+
return $"{base.ToString()}|{Text}";
2317
}
2418
}

Chapter05/Components/LinkButton.cs

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
using Chapter05.Contracts;
22

3-
namespace Chapter05.Components
3+
namespace Chapter05.Components;
4+
5+
public class LinkButton(int id, string name, (double, double) position)
6+
: ButtonBase(id, name, position), IDrawable
47
{
5-
public class LinkButton
6-
: ButtonBase, IDrawable
8+
public Uri Url { get; set; }
9+
10+
public void Draw()
11+
{
12+
Console.WriteLine("LinkButton draw at {0}:{1}", Position.Item1, Position.Item2);
13+
}
14+
public override string ToString()
715
{
8-
public Uri Url { get; set; }
9-
public LinkButton(int id, string name, (double, double) position)
10-
: base(id, name, position)
11-
{
12-
}
13-
public void Draw()
14-
{
15-
Console.WriteLine("LinkButton draw at {0}:{1}", Position.Item1, Position.Item2);
16-
}
17-
public override string ToString()
18-
{
19-
return $"{base.ToString()}|{Url}";
20-
}
16+
return $"{base.ToString()}|{Url}";
2117
}
2218
}

Chapter05/Components/RadioButton.cs

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
using Chapter05.Contracts;
22

3-
namespace Chapter05.Components
3+
namespace Chapter05.Components;
4+
5+
public class RadioButton(int id, string name, (double, double) position)
6+
: ButtonBase(id, name, position), IDrawable
47
{
5-
public class RadioButton
6-
: ButtonBase, IDrawable
8+
public List<string> Options { get; set; } = [];
9+
public string SelectedOption { get; set; }
10+
11+
public void Draw()
12+
{
13+
Console.WriteLine("RadioButton draw at {0}:{1}", Position.Item1, Position.Item2);
14+
}
15+
public override string ToString()
716
{
8-
public List<string> Options { get; set; } = [];
9-
public string SelectedOption { get; set; }
10-
public RadioButton(int id, string name, (double, double) position)
11-
: base(id, name, position)
12-
{
13-
}
14-
public void Draw()
15-
{
16-
Console.WriteLine("RadioButton draw at {0}:{1}", Position.Item1, Position.Item2);
17-
}
18-
public override string ToString()
19-
{
20-
return $"{base.ToString()}|{SelectedOption}";
21-
}
17+
return $"{base.ToString()}|{SelectedOption}";
2218
}
2319
}

0 commit comments

Comments
 (0)