I have a question, here is an example
I have a Model class: Stock
public class Stock{
//some properties, stock name, stock code;
public String StockName{
get,set
}
public String StockCode{
get,set
}
}
Also I have a service class StockService, which will load the data from database and create the stock and setting the properties value.
public class StockService:IStockService{
public Stock CreateStockByStockCode(string stockCode){
Stock stock = new Stock();
//load the data from db and set the stock's properties.
stock.StockName = ...
stock.StockCode = ...
}
}
so, my question, i have a "Save()" method, where should I put,
Option1 : put it in the Stock class,
public class Stock{
public void Save(){
//use the repository to save into db.
}
}
Option2: put it in the service class
public class StockService:IStockService{
public void Save(Stock stock){
//use the repository to save into db.
}
}
i think for the option1: the stock seems a little smart, it can save itself and more ojbect-oriented. And for the option2, I saw a lot of guys use this kind of pattern. What's you idea?