This is the first web app that i am building by myself.
Before coding i like to organize my ideas, do class and requiriments diagrams.
So i have to do this in my software
-Add users. -Add buy orders.
I am thinking my classes in two different ways.
Like this:
class User{
function add()
function edit()
}
class BuyOrder{
function add()
function edit()
}
Or
class Add{
function user()
function buyOrder()
}
class Edit{
function user()
function buyOrder()
}
As you can see they will do the same but with different writting.
Any ideas?
thanks
I think User and BuyOrder should be a class.
However, it doesn't make sense to me to have an add function be a part of these classes since the creation of a new instance of these classes effectively is the add.
Instead I would create AddUser and AddOrder functions which create the instances and properly add them where they need to be.
public class User
{
public Guid Id { get; set; }
public string Name { get; set; }
pubic string LastName { get; set; }
public byte Age { get; set; }
public List<Order> Orders { get; set; }
}
public class Order
{
public Guid Id { get; set; }
public decimal Price { get; set; }
public bool IsAvailable { get; set; }
}
public class Service
{
public User Create(User user) { };
public User Read(Guid id) { };
public void Update(User user) { };
public void Delete(Guid id) { };
public Order Create(Order order) { };
public Order Read(Guid id) { };
public void Update(Order order) { };
public void Delete(Guid id) { };
// Add orders to user basket
public void AddOrdersToUserBasket(List<Order> orders, User user) { };
public void AddOrdersToUserBasket(List<Order> orders, Guid id) { };
// Get all orders of current user
public List<Order> ReadOrdersForUser (Guid id) { };
// Send orders and user data to process a delivery.
public void Send ProcessOrdersAndUserData(List<Order> orders, User user) { };
}
Instead of void as return value, you can use the some wrapper:
public class Answer
{
public bool Result { get; set; }
public string Message { get; set; }
}
And need to divide the service to UserSevice, OrderService and ProcessService.