Repository Pattern vs data access in domain objects

Hello, first of all I am very new to development.

I am wondering what's better, accessing data thru a Repository Pattern class or having the data access coded inside the domain objects:

// Repository pattern Order order = DataAccess.GetOrder(orderID); // OOP Order newOrder = Order.Get(orderID); 

I've been reading about the anemic object anti-pattern by Martin Fowler, and I am wondering if having a Repository Pattern and objects that only hold the data (Business entities) is bad practice and instead I should have full classes that encapsulates the business logic, data access functionality and of course also hold the data.

What's the best approach?

Thanks

by newbie_developer via /r/csharp

Leave a Reply