Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / December 2005

Tip: Looking for answers? Try searching our database.

Question about design

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gabriel Lozano-Morán - 08 Dec 2005 19:24 GMT
Assume that you have a Document class that you want to persist. Which
solution would be better and what are the advantages/disadvantages of each
approach?

Document doc = new Document();

1)
doc.Persist(PersistType.CsvDelimited);

2)
CsvPersister persister = new CsvPersister(Document);
persister.Persist();

I would go for solution 1 because the the Persist() operation is a
responsibility of the Document. But several of my coworkers will go for
solution 2 without arguing about it. Personally I find solution 2 a good
solution if you want to use the same persister for several different types
like the XmlSerializer class.

If you go for solution 2 where do you draw the line? I mean you could then
write a class for each public operation of the document?

I appreciate any feedback

Gabriel
Gabriel Lozano-Morán - 08 Dec 2005 19:40 GMT
Also how about the following approach:

Document doc = new Document();
doc.Persist(new CsvPersister())

and in the Persist of the Document:

public void Persist(IPersister persister)
{
   persister.Persist(this);
}
Charles Law - 09 Dec 2005 10:33 GMT
Hi Gabriel

I think this crops up in many similar scenarios, for example users and
roles. Does a User object maintain a list of roles to which it belongs, or
does a Role object maintain a list of Users who have that role, or both.

In your scenario, I would say that if your Document object implements some
common (to your application) interface, such as IPersistable, then solution
2 would work well. Your CsvPersister would not need to understand how to
persist a document, only how to persist an object that implements
IPersistable. It also implies that you have a common format that you would
use for a variety of persistable objects.

On the other hand, if you only have one or two objects that will be
persisted, and each in a different way, then I would promote solution 1.

HTH

Charles

> Assume that you have a Document class that you want to persist. Which
> solution would be better and what are the advantages/disadvantages of each
[quoted text clipped - 21 lines]
>
> Gabriel

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.