Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q2-Review #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Interfaces/IAnimalSound.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Refactored.Interfaces
{
public interface IAnimalSound
{
void MakeSound();
}
}
15 changes: 15 additions & 0 deletions Interfaces/IDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Refactored.Interfaces
{
public interface IDatabase
{
void Save(string input, string timestamp);

string Retrieve(int index);
}
}
13 changes: 13 additions & 0 deletions Interfaces/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Refactored.Interfaces
{
public interface ILogger
{
void Log(string message);
}
}
21 changes: 21 additions & 0 deletions Interfaces/ISalaryCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Refactored.Interfaces
{
public interface ISalaryCalculator
{
string CalculateSalary(long userId);
}

public class SalaryCalculator : ISalaryCalculator
{
public string CalculateSalary(long userId)
{
return (userId * 1100 - userId).ToString();
}
}
}
14 changes: 14 additions & 0 deletions Interfaces/IZookeeperManager.cs
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;
using Refactored.Model;

namespace Refactored.Interfaces
{
public interface IZookeeperManager
{
void ProcessSalaries(IEnumerable<Zookeeper> zookeepers);
}
}
17 changes: 17 additions & 0 deletions Model/ConsoleLogger.cs
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;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class ConsoleLogger : ILogger
{
public void Log(string message)
{
Console.WriteLine(message);
}
}
}
17 changes: 17 additions & 0 deletions Model/Elephant.cs
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;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class Elephant : IAnimalSound
{
public void MakeSound()
{
Console.WriteLine("Elephant Sound");
}
}
}
18 changes: 18 additions & 0 deletions Model/Giraffe.cs
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;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class Giraffe : IAnimalSound
{
public void MakeSound()
{
Console.WriteLine("Giraffe Sound");
}
}

}
17 changes: 17 additions & 0 deletions Model/Lion.cs
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;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class Lion : IAnimalSound
{
public void MakeSound()
{
Console.WriteLine("Lion Sound");
}
}
}
17 changes: 17 additions & 0 deletions Model/Monkey.cs
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;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class Monkey : IAnimalSound
{
public void MakeSound()
{
Console.WriteLine("Monkey Sound");
}
}
}
38 changes: 38 additions & 0 deletions Model/MyDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class MyDatabase : IDatabase
{
private ILogger _logger;
public MyDatabase(ILogger logger)
{
_logger = logger;

}
private readonly List<string> _data = new List<string>();

public void Save(string input, string timestamp)
{
_data.Add(input + "|" + timestamp);
_logger.Log("Data Saved: " + input + "|" + timestamp);
}

public string Retrieve(int index)
{
if (index < 0 || index >= _data.Count)
{
_logger.Log("No data");
throw new Exception("No Data");
}
return _data[index];
}


}
}
33 changes: 33 additions & 0 deletions Model/Zoo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class Zoo
{
private readonly List<IAnimalSound> _animals;

public Zoo()
{
_animals = new List<IAnimalSound>
{
new Lion(),
new Elephant(),
new Giraffe(),
new Monkey()
};
}

public void MakeAnimalSounds()
{
foreach (var animal in _animals)
{
animal.MakeSound();
}
}
}
}
14 changes: 14 additions & 0 deletions Model/Zookeeper.cs
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 Refactored.Model
{
public class Zookeeper
{
public long Id { get; set; }
public string Email { get; set; }
}
}
31 changes: 31 additions & 0 deletions Model/ZookeeperManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Refactored.Interfaces;

namespace Refactored.Model
{
public class ZookeeperManager : IZookeeperManager
{
private readonly IDatabase _database;
private readonly ISalaryCalculator _salaryCalculator;

public ZookeeperManager(IDatabase database, ISalaryCalculator salaryCalculator)
{
_database = database;
_salaryCalculator = salaryCalculator;
}

public void ProcessSalaries(IEnumerable<Zookeeper> zookeepers)
{
foreach (var zookeeper in zookeepers)
{
var salary = _salaryCalculator.CalculateSalary(zookeeper.Id);
_database.Save(salary, "Salary paid");
}
}
}

}