Answered by:
architect: needs opinions based on design guidelines .

Question
-
User888441741 posted
hi there...
i just want to make sure that i am folling the correct pattern and following the right practice and i have read the book (Wrox.Professional.Enterprise.dot.NET) and based on that book here is what i come-up with my design.
my solution consists of:
Model,
Repository,
Service,
Test,
UI
so is that resanable design? any advice? any help improving more?
please feel free to have your inputs.
thanks for looking.
Wednesday, February 17, 2010 2:10 PM
Answers
-
User-2074625069 posted
my curiosity is more increased now
what do you think of my design is more like Domain Model or DTO
if my design is not DTO then can you show me some sample lines of code how DTO would be looks like?
At the moment you have an anemic domain model (http://en.wikipedia.org/wiki/Anemic_Domain_Model) which is fine, this may be due to a lack of business rules in the real world so no rules in your model, or it may ber due to you wanting to add the rules to seperate validation or business rules classes. A Domain Model design would have behaviour as well as data on the business entities, so instead of simple object with getters and setters you would have business methods - Does that make sense?
I will write a couple of simple projects and upload them to show the difference.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, February 19, 2010 5:07 AM
All replies
-
User-952121411 posted
I don't see anything incorrect about the design just glancing over the code, but if you want some opinions based on design guidelines from that specific book you may want to check out the following forum:
BOOK: Professional Enterprise .NET Forum:
http://p2p.wrox.com/book-professional-enterprise-net-523/
The actual authors of that book monitor that forum and may give you the best feedback.
Wednesday, February 17, 2010 3:38 PM -
User-758443495 posted
hi dear,
you wrote correct code,but remember that architect and patterns are depended on the project that you are working on
so with my +6years experience in architecture and design I suggest you that try to understand the usage of patterns and correct place of them and the code style try to many best parcties and define new samples with your self more and more
architect and true usage of patterns is really important in enterprise applications and they need more attention and good undetanding
hope that you be a perfect architect very soon
Wednesday, February 17, 2010 4:49 PM -
User-2074625069 posted
Hi nisarkha,
First off thanks for buying my book
Having a look at your code your service class seems a little mixed up. From Fowlers book on Patterns of Enterprise Arch the service layer...
"...defines an application's boundary [Cockburn PloP] and its set of available operations from the perspective of interfacing client layers. It encapsulates the application's business logic, controlling transactions and coor-dinating responses in the implementation of its operations." ~ http://martinfowler.com/eaaCatalog/serviceLayer.htmlSo I would modify the service layer like so:
public class EscortService : IEscortService { private IEscortRepository _escortRepository; public EscortService(IEscortRepository escortRepository) { _escortRepository = escortRepository; } public List<PartialPerson> LoadEscort() { // Could cache the response from the repository // do something else with the list of PartialPerson return _escortRepository.LoadEscort(); } }
With the modified code you can now unit test the service class, plus the responsiblity of obtainig the respository is now not the concern of the service due to the fact that we are now injecting it into the class via the constructor - dependency injection.
If you were being pragmatic you might not want a service layer at all as its not really giving you anything. However if you wanted to cache the results from the repository or indeed perform some other bit of business logic then the service layer would start becoming useful.
I hope that was of some use. let me know if you have any more questions.
Cheers Scott
Thursday, February 18, 2010 12:32 PM -
User888441741 posted
Hi Scott,
Thank you for the great book and its worth every penny :), i will highly recommend to other folks....
yes you are absolutely correct about my service layer.... yesterday i was reading the article and i realize that i have tightly coupled Service (http://dotnetslackers.com/articles/aspnet/Building-a-StackOverflow-inspired-Knowledge-Exchange-Three-Tiers-to-MVC-Hooray-Dependency-Injection.aspx) -
what is the best place to have my business logic?/caching my data?
will that be in another layer called Business Layer? or Service layer or should I rename Service to Business Layer?
any thoughts?
Thanks for your time.
Thursday, February 18, 2010 12:52 PM -
User-2074625069 posted
Hi nisarkhan,
Because you are using a interface to communicate with the repository you can create a caching layer that your service can use, somthing like:
public class EscortRepositoryWithCache : IEscortRepository { Private IEscortRepository _realEscortRepository; Private ICacheStorage _cacheStroage; public EscortRepositoryWithCache(IEscortRepository realEscortRepository, ICacheStorage cacheStroage) { _realEscortRepository = realEscortRepository; _cacheStroage = cacheStroage; } public List<PartialPerson> LoadEscort() { List<PartialPerson> people = (List<PartialPerson>)_cacheStroage.Get("PeopleKey"); if (people == null) { people _realEscortRepository.LoadEscort(); _cacheStroage.Put("PeopleKey", people); } return people; } }
With regard to business logic it depends what you want to do. At the moment your domain entity doesn't seem to have any business logic this may be because there isn't any or because you haven't added yet. You need to decide if you want to use DTO's (objects with getters and setters used for transporting data around) or a full blown domain model (entites with behavior and data). If you are going for a domain model, check out chapter 7 or read up about the Domain Model pattern (http://martinfowler.com/eaaCatalog/domainModel.html), if you want to use DTO's then you can add the business logic to the service class.
When I write big projects my business layer contains:- Domain Services - http://devlicio.us/blogs/casey/archive/2009/02/17/ddd-services.aspx
- Domain Model - http://en.wikipedia.org/wiki/Domain_model
Then I have a seperate Application Service layer that would return ViewModels back to the presentation layer. If you are using DTO's you can simply return these to the presentation layer. The project from the book uses a domain model, check it out here - http://www.codeplex.com/ProEnt.
Here is a diagram on how it is all layed out:Thank you for the great book and its worth every penny :), i will highly recommend to other folks....
thanks, if you get the chance could you add a review to amazon?
Thursday, February 18, 2010 2:18 PM -
User888441741 posted
Hi nisarkhan,
Because you are using a interface to communicate with the repository you can create a caching layer that your service can use, somthing like:
- public class EscortRepositoryWithCache : IEscortRepository
- {
- Private IEscortRepository _realEscortRepository;
- Private ICacheStorage _cacheStroage;
- public EscortRepositoryWithCache(IEscortRepository realEscortRepository,
- ICacheStorage cacheStroage)
- {
- _realEscortRepository = realEscortRepository;
- _cacheStroage = cacheStroage;
- }
- public List<PartialPerson> LoadEscort()
- {
- List<PartialPerson> people = (List<PartialPerson>)_cacheStroage.Get("PeopleKey");
- if (people == null)
- {
- people _realEscortRepository.LoadEscort();
- _cacheStroage.Put("PeopleKey", people);
- }
- return people;
- }
- }
public class EscortRepositoryWithCache : IEscortRepository { Private IEscortRepository _realEscortRepository; Private ICacheStorage _cacheStroage; public EscortRepositoryWithCache(IEscortRepository realEscortRepository, ICacheStorage cacheStroage) { _realEscortRepository = realEscortRepository; _cacheStroage = cacheStroage; } public List<PartialPerson> LoadEscort() { List<PartialPerson> people = (List<PartialPerson>)_cacheStroage.Get("PeopleKey"); if (people == null) { people _realEscortRepository.LoadEscort(); _cacheStroage.Put("PeopleKey", people); } return people; } }
the above code snippet is suppose to Service correct? public class EscortServiceWithCache : IEscortRepository ....
With regard to business logic it depends what you want to do. At the moment your domain entity doesn't seem to have any business logic this may be because there isn't any or because you haven't added yet. You need to decide if you want to use DTO's (objects with getters and setters used for transporting data around) or a full blown domain model (entites with behavior and data). If you are going for a domain model, check out chapter 7 or read up about the Domain Model pattern (http://martinfowler.com/eaaCatalog/domainModel.html), if you want to use DTO's then you can add the business logic to the service class.I thought i am using DTO's if you see my class PartialVisitor which is a value object and the purpose of that class is to transport data around
or may be i am consfused now
Can I send you sample application if you dont mind? for review?
Thanks.
Thank you for the great book and its worth every penny :), i will highly recommend to other folksthanks, if you get the chance could you add a review to amazon? ....
I get this error when i try to post ** You must have purchased items from Amazon to post.
Thursday, February 18, 2010 4:38 PM -
User888441741 posted
my curiosity is more increased now
what do you think of my design is more like Domain Model or DTO
if my design is not DTO then can you show me some sample lines of code how DTO would be looks like?
i will see the capter 7 again for Domain Model
Thanks.
Thursday, February 18, 2010 5:02 PM -
User-2074625069 posted
the above code snippet is suppose to Service correct? public class EscortServiceWithCache : IEscortRepository ....
The EscortServiceWithCache class can be used with the service like so:
IEscortRepository realRepository = new SQLServerEscortRepository(); ICacheStorage cachingStorage = new ASPWebCacheStorage(); IEscortRepository cachingRepository = new EscortRepositoryWithCache(realRepository, cachingStorage); EscortService service = new EscortService(cachingRepository);
This way the Servic is unaware of where the data is coming from and if its cached or not.
Yes you can send me some code to Scott at elbandit dot co dot uk.
Friday, February 19, 2010 4:18 AM -
User-2074625069 posted
my curiosity is more increased now
what do you think of my design is more like Domain Model or DTO
if my design is not DTO then can you show me some sample lines of code how DTO would be looks like?
At the moment you have an anemic domain model (http://en.wikipedia.org/wiki/Anemic_Domain_Model) which is fine, this may be due to a lack of business rules in the real world so no rules in your model, or it may ber due to you wanting to add the rules to seperate validation or business rules classes. A Domain Model design would have behaviour as well as data on the business entities, so instead of simple object with getters and setters you would have business methods - Does that make sense?
I will write a couple of simple projects and upload them to show the difference.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, February 19, 2010 5:07 AM -
User888441741 posted
Yes you can send me some code to Scott at elbandit dot co dot uk.Scott, I email you if you get chance please have a look at it. - thanks
I will write a couple of simple projects and upload them to show the difference.please let me know when you upload.
Friday, March 5, 2010 11:51 AM -
User-2074625069 posted
Hi Nisarkhan,
Sorry for the delay have been busy, here are the examples:I haven't check my email for a few days so I will take a look.
Cheers
ScottFriday, March 5, 2010 3:26 PM -
User-967169866 posted
Scott, I think you totally nailed this one. I'm actually quite impressed.
Sunday, March 7, 2010 6:27 AM -
User-2074625069 posted
ta
Sunday, March 7, 2010 6:42 AM -
User888441741 posted
Hi Nisarkhan,
Sorry for the delay have been busy, here are the examples:I haven't check my email for a few days so I will take a look.
Cheers
ScottThanks Scott.
please bare with me and i have noticed that in Domain Model Example you are not using any DTO's instead you use prop (internal set) is there any reason for not using DTO's?
if you have used, where would you put them (assume that you have around 20 classes)
will you put them in a seprate assembley App.DTO? also would you suggust to create interface for DTOs?
thoughts?
Monday, March 8, 2010 10:49 AM -
User-2074625069 posted
please bare with me and i have noticed that in Domain Model Example you are not using any DTO's instead you use prop (internal set) is there any reason for not using DTO's?I am using DTO's in the Domain Model solution, they can be found in the AppService project within the ViewModel folder. I am using DTO's for the use as described by fowler in his PofEAA book.
if you have used, where would you put them (assume that you have around 20 classes)
will you put them in a seprate assembley App.DTO? also would you suggust to create interface for DTOs?
I am not quite sure I follow, the Domain Model project shows the use of a rich(ish) domain model as opposed to DTO's you asked to see this. The other project "Anemic Model Example" uses DTO's for business objects and yes in this project you could seperate the DTO's into their own project.
Monday, March 8, 2010 6:38 PM -
User888441741 posted
Thanks Scott.
Thanks for the clarification i do see the ViewModel, first i thought those are entitties because value objects (i am assuming dto and value objects are same) should be Getter only? is that not correct?
DTO having interface:
what i was asking is that, let say i have created DTO class called "PartialVisitorDTO" and PartialVisitorDTO has some properties like (FirstName, LastName,Age...etc)
is that a good practice or rather recommend to create interface for PartialVisitorDTO ? something like IPartialVisitorDTO ?
Thanks a lot.
Monday, March 8, 2010 7:36 PM -
User-2074625069 posted
Thanks for the clarification i do see the ViewModel, first i thought those are entitties because value objects (i am assuming dto and value objects are same) should be Getter only? is that not correct?Have a read of these two articles, I think some things refer to DTO's as Value Objects. I understand value objects from the DDD methodology
Value Objects
"The key defining characteristic of a Value Objects is that it has no Identity. Ok, perhaps a little simplistic, but the intention of a Value Object is to represent something by it’s attributes only. Two VOs may have identical attributes, in which case they are identical. They don’t however have any value other than by virtue of their attributes.Another aspect common to VOs is that they should probably be immutable, once created they cannot be changed or altered. You can create a new one, and as they have no identity, that is just the same as changing another one.
Examples of common Value Objects: Money, Address, ProductCode"
from http://devlicio.us/blogs/casey/archive/2009/02/13/ddd-entities-and-value-objects.aspxData Transfer Objects
"...The solution is to create a Data Transfer Object that can hold all the data for the call. It needs to be serializable to go across the connection. Usually an assembler is used on the server side to transfer data between the DTO and any domain objects..."
from http://martinfowler.com/eaaCatalog/dataTransferObject.htmlDTO having interface:
what i was asking is that, let say i have created DTO class called "PartialVisitorDTO" and PartialVisitorDTO has some properties like (FirstName, LastName,Age...etc)
is that a good practice or rather recommend to create interface for PartialVisitorDTO ? something like IPartialVisitorDTO ?
Thanks a lot.
As a DTO is just a simple method for transferrring data the PartialVisitorDTO shouldn't contain any behaviour (methods, logic etc) so I wouldn't normally create an interface for it, but if you want to there is no problem with it.Tuesday, March 9, 2010 3:40 AM