Skip to content

Wyulliam/portfolio-basic-anthill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 

Repository files navigation

WORK IN PROGRESS

Before going thru this project, keep in mind that it is in progress. This are the main things that are waiting to be developed:

  • Integration Tests: test the application after Entity Framework
  • Life and death of ants: after being born, ants are supposed to die after a while

What is this project?

This is a simple project that is part of my online portfolio. The objective of the portfolio is to pratice and keep track of my designing skills.

This project is an Anthill. Here, you are the Queen of the Anthill and you have the power to lay new eggs of any type of ants. These ants are born, live for a while and die. It is a simple console application used to test the code.

What you are not going to find in this project

These topics are not present in this project. They will have their own project in the near future:

  • REST/Web API
  • MEP

What you are going to find in this project

.NET Core

.NET Core because you, the reader, may not be using Windows OS.

Entity Framework

Used to create a code-first application. This way, we can generate the database based on our entities. It is responsible to create, read, update and delete code without using raw SQL commands.

With entity framework, I'm using a simple SQLite database, since there is no need, in this project, for a SQL Server database or similar. Entity Framework is a good call because we can change the SQLite database for an SQL Server, for example, and we would only change the connection string in the Context classes.

MediatR

With MediatR we can send commands/events inside our application, meaning we can decouple the implementations. The Nursery, for example, doesn't need to know that the Incubator is the responsible for incubating eggs, the Nursery just send a command and it knows that someone will handle the request.

TDD

Using Test Driven Development on your project will not only make it less susceptible to bugs, it will increase your productivity and make your code way more clean. In this project, my approach was to create the Queen's implementation, and start unit testing its functions, using interfaces that were not even implemented. This way, I can guarantee that the Queen's implementation is working the way it is supposed to work. After that, I implemented the next interface, and started unit testing it the same way, and so it goes.

To achive this simplicity into testing implementation using only interfaces, I used NSubstitute where you can mock your interfaces and guarantee they received calls with the expected parameters. I also used Fluent Assertions to facilitate the assertions of the tests.

SOLID principles

Single Responsability

Classes and Interfaces should have only one reason to change. All the classes and interfaces have only one responsability, low or high level. Take for example, the AntTypeRepository: its responsability is to get/save ant types, while the Queen, even if it needs to do multiple tasks, its only responsability is to manage the Anthill.

Open Closed

Code should be open to extensions, but closed to modifications. In this project, we have a Nursery, where it care for the ant eggs. The Queen will always have access to the Nursery methods, even if we decided to create a SpecialNursery. We could give the Queen a whole new Nursery without needing to change any Queen's behaviour.

Interface Segregation

One class should not depend on an interface with methods that the class does not use. If your class implements more methods that it should, you are probably using the wrong abstraction.

Dependency Injection

With Dependency Injection, class are not bounded directly to another classes implementation. Rather than creating a new instance of a class inside your code, you "inject" it in its constructor, decoupling them and making it easier for changes.

Abstract Factories

All the high level interfaces in this project (Nursery, Colony and Cemtery) use an abstract factory to create all the services necessary. This way, we know that the Nursery, for example, will always have an EggGenerator. The nursery don't need to know if the EggGenerator is a DefaultEggGenerator, a SpecialEggGenerator or a MagicalEggGenerator. The factory has the responsability to provide the right EggGenerator.

Repository Pattern

Using the Repository Pattern, we can make our code persistence ignorant. It does not need to know if the eggs are being saved at an SQL Server database, a JSON file or even being sent to the cloud. The code knows that there is an Interface that save the eggs. This interface is at the Core project while its implementation is at the Data project

References

About

This project is part of my Git hub portfolio. This is a basic project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages