Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Saving Business Objects

Saving Business Objects

Scheduled Pinned Locked Moved Design and Architecture
questioncsharpdockerbusinesslearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CodingYoshi
    wrote on last edited by
    #1

    Lets say I have 3 classes: Category, Book, and BookCollection. Objects of Category class will have a BookCollection which is simply some container which contains all the books within that category. These classes also have a method Save() which saves them to a permanent storage. Now when Category's Save() method is called, should it just save the category or the books within the category as well? What are the advantages and disadvantages? If Category.Save() only saves itself, then clients will also need to call Category.Books.Save(). What is better? Also, should BookCollection.Save() traverse the books and call Save on each or will it do all the saving? I guess it depends on the context but is there a convention?

    CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07

    L 1 Reply Last reply
    0
    • C CodingYoshi

      Lets say I have 3 classes: Category, Book, and BookCollection. Objects of Category class will have a BookCollection which is simply some container which contains all the books within that category. These classes also have a method Save() which saves them to a permanent storage. Now when Category's Save() method is called, should it just save the category or the books within the category as well? What are the advantages and disadvantages? If Category.Save() only saves itself, then clients will also need to call Category.Books.Save(). What is better? Also, should BookCollection.Save() traverse the books and call Save on each or will it do all the saving? I guess it depends on the context but is there a convention?

      CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, this is how I see it: 1. a phone directory holds a number of phone numbers; the phone numbers are not saved separately, it is the directory that holds them. 2. a filesystem directory holds (or seems to hold?) a number of files; however you can read and write files without explicitly accessing their directory, so the file is a real object. The directory basically is just holding information on files (say FileInfo objects, which do not get saved separately). 3. now which of those two cases your Book application ressembles most? if you want to save and restore individual books, use (2) and threat your BookCollection as a list of book references, so saving that would be e.g. a file containing book/file names. if wou do not want to save and restore individual books, use (1) BTW: I am not convinced your Category class makes much sense, IMO Category would be an enum, and each book would have a Category property; you Category class could just be another BookCollection holding some of the Books (the once with matching Category property), or an enumerator inside BookCollection yielding only the Books with matching category. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      C 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, this is how I see it: 1. a phone directory holds a number of phone numbers; the phone numbers are not saved separately, it is the directory that holds them. 2. a filesystem directory holds (or seems to hold?) a number of files; however you can read and write files without explicitly accessing their directory, so the file is a real object. The directory basically is just holding information on files (say FileInfo objects, which do not get saved separately). 3. now which of those two cases your Book application ressembles most? if you want to save and restore individual books, use (2) and threat your BookCollection as a list of book references, so saving that would be e.g. a file containing book/file names. if wou do not want to save and restore individual books, use (1) BTW: I am not convinced your Category class makes much sense, IMO Category would be an enum, and each book would have a Category property; you Category class could just be another BookCollection holding some of the Books (the once with matching Category property), or an enumerator inside BookCollection yielding only the Books with matching category. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        C Offline
        C Offline
        CodingYoshi
        wrote on last edited by
        #3

        Thanks for the reply. This is not a real application so the classes are just "hypothetically speaking". However, if it was a real application, Category can still be a valid class because you can create, delete, modify categories as well. Then category will have more properties like id, name, description, books etc. If it is an enum then we can not accommodate the above. Nonetheless, your answer really helped me.

        CodingYoshi Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups