OO question beginner

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • .net lear

    OO question beginner

    if I have an object, say a recipe, which is added to a database, whose
    responsibility is it to add to the db? The recipe or something else?

    Let's say I want to delete a recipe? Does the recipe kill itself? Or does
    the database or something else do the removal?

    Where does the responsibility lie?

    Thanks.



  • Nick Malik [Microsoft]

    #2
    Re: OO question beginner

    Usually, you will use the Layers pattern (see Buschmann) and you would
    seperate the business object (recipe) from the CRUD code needed to insert or
    delete it from the database (in the persistence layer)

    The object itself is responsible for using the persistence layer, and for
    knowing what methods to call to persist its data.

    So, a recipe stores itself using the persistence layer, and a recipe deletes
    itself using the persistence layer.

    --
    --- Nick Malik [Microsoft]
    MCSD, CFPS, Certified Scrummaster


    Disclaimer: Opinions expressed in this forum are my own, and not
    representative of my employer.
    I do not answer questions on behalf of my employer. I'm just a
    programmer helping programmers.
    --
    ".net lear" <asdfasdf> wrote in message
    news:uufQm7MeFH A.712@TK2MSFTNG P12.phx.gbl...[color=blue]
    > if I have an object, say a recipe, which is added to a database, whose
    > responsibility is it to add to the db? The recipe or something else?
    >
    > Let's say I want to delete a recipe? Does the recipe kill itself? Or does
    > the database or something else do the removal?
    >
    > Where does the responsibility lie?
    >
    > Thanks.
    >
    >
    >[/color]


    Comment

    • .net lear

      #3
      Re: OO question beginner

      ok thanks. I thought the recipe would be responsible but I don't know
      anything about the persistence layer.


      "Nick Malik [Microsoft]" <nickmalik@hotm ail.nospam.com> wrote in message
      news:xeqdneenh9 JHviHfRVn-iA@comcast.com. ..[color=blue]
      > Usually, you will use the Layers pattern (see Buschmann) and you would
      > seperate the business object (recipe) from the CRUD code needed to insert[/color]
      or[color=blue]
      > delete it from the database (in the persistence layer)
      >
      > The object itself is responsible for using the persistence layer, and for
      > knowing what methods to call to persist its data.
      >
      > So, a recipe stores itself using the persistence layer, and a recipe[/color]
      deletes[color=blue]
      > itself using the persistence layer.
      >
      > --
      > --- Nick Malik [Microsoft]
      > MCSD, CFPS, Certified Scrummaster
      > http://blogs.msdn.com/nickmalik
      >
      > Disclaimer: Opinions expressed in this forum are my own, and not
      > representative of my employer.
      > I do not answer questions on behalf of my employer. I'm just a
      > programmer helping programmers.
      > --
      > ".net lear" <asdfasdf> wrote in message
      > news:uufQm7MeFH A.712@TK2MSFTNG P12.phx.gbl...[color=green]
      > > if I have an object, say a recipe, which is added to a database, whose
      > > responsibility is it to add to the db? The recipe or something else?
      > >
      > > Let's say I want to delete a recipe? Does the recipe kill itself? Or[/color][/color]
      does[color=blue][color=green]
      > > the database or something else do the removal?
      > >
      > > Where does the responsibility lie?
      > >
      > > Thanks.
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • John Timney \(ASP.NET MVP\)

        #4
        Re: OO question beginner

        The recipe only tells you how to cook the dish, it has no concept of where
        the recipe is stored in your kitchen. As it happens its stored in the
        cookbook (the persistence or data layer). storing the recipe has nothing to
        do with cooking the dish, so you should refrain from including that logic in
        your business layer (the recipe) - ideally the cookbook would do the
        deletions and inserts with the recipe being an argument passed to it as the
        persistence layer as inserts and deletions are something that occur to your
        cookbook not your recipe.

        --
        Regards

        John Timney
        ASP.NET MVP
        Microsoft Regional Director

        --
        Regards

        John Timney
        ASP.NET MVP
        Microsoft Regional Director

        ".net lear" <asdfasdf> wrote in message
        news:uufQm7MeFH A.712@TK2MSFTNG P12.phx.gbl...[color=blue]
        > if I have an object, say a recipe, which is added to a database, whose
        > responsibility is it to add to the db? The recipe or something else?
        >
        > Let's say I want to delete a recipe? Does the recipe kill itself? Or does
        > the database or something else do the removal?
        >
        > Where does the responsibility lie?
        >
        > Thanks.
        >
        >
        >[/color]


        Comment

        • JV

          #5
          Re: OO question beginner

          Well put!

          "John Timney (ASP.NET MVP)" <timneyj@despam med.com> wrote in message
          news:%23ObJOlNe FHA.1448@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > The recipe only tells you how to cook the dish, it has no concept of where
          > the recipe is stored in your kitchen. As it happens its stored in the
          > cookbook (the persistence or data layer). storing the recipe has nothing
          > to do with cooking the dish, so you should refrain from including that
          > logic in your business layer (the recipe) - ideally the cookbook would do
          > the deletions and inserts with the recipe being an argument passed to it
          > as the persistence layer as inserts and deletions are something that occur
          > to your cookbook not your recipe.[/color]


          Comment

          • .net lear

            #6
            Re: OO question beginner

            Thanks a lot.

            I'm just getting started with this concept, very used to procedural
            programming.

            Isn't the cookbook just a collection of recipes? In other words,
            doesn't it inherit from recipe to some degree?

            When you say "stored in the cookbook (persistence or data layer)", can
            you elaborate? What does that mean?


            John Timney (ASP.NET MVP) wrote:[color=blue]
            > The recipe only tells you how to cook the dish, it has no concept of where
            > the recipe is stored in your kitchen. As it happens its stored in the
            > cookbook (the persistence or data layer). storing the recipe has nothing to
            > do with cooking the dish, so you should refrain from including that logic in
            > your business layer (the recipe) - ideally the cookbook would do the
            > deletions and inserts with the recipe being an argument passed to it as the
            > persistence layer as inserts and deletions are something that occur to your
            > cookbook not your recipe.
            >
            > --
            > Regards
            >
            > John Timney
            > ASP.NET MVP
            > Microsoft Regional Director
            >
            > --
            > Regards
            >
            > John Timney
            > ASP.NET MVP
            > Microsoft Regional Director
            >
            > ".net lear" <asdfasdf> wrote in message
            > news:uufQm7MeFH A.712@TK2MSFTNG P12.phx.gbl...[color=green]
            > > if I have an object, say a recipe, which is added to a database, whose
            > > responsibility is it to add to the db? The recipe or something else?
            > >
            > > Let's say I want to delete a recipe? Does the recipe kill itself? Or does
            > > the database or something else do the removal?
            > >
            > > Where does the responsibility lie?
            > >
            > > Thanks.
            > >
            > >
            > >[/color][/color]

            Comment

            • John Timney \(ASP.NET MVP\)

              #7
              Re: OO question beginner

              How it inherits depends on your encapsulation, and whether there is any
              interaction between the cookbook and the recipe. In an ideal OO scanrio the
              recipe should be self contained, telling you only how to make the dish. The
              cookbook knows nothing about making the dish, thus it needs to inherit none
              of the properties of the recipe to function as a cookbook - it only needs to
              contain recipe objects, like a namespace containing lots of different
              classes. The classes in the namespace can be interelated by existing in the
              namespace, but need not know anything about each other unless thats how to
              need the objects to interact. Connected to this, the way you serve the
              recipe (the presentation (layer)) has nothing to do with how it is stored in
              the cookbook (persistence (layer)) or how it is cooked (business (layer))

              Mutli tiered or layered implementations perform different and self contained
              elements of your programming logic, like your presentation layer knowing
              about plates and cress but nothing about cooking times. Theres a very nice
              and straingtforward explanation of multi tiered applications here that might
              be worth taking a look at.

              Microsoft Visual FoxPro, Microsoft SQL-Server, Microsoft FoxPro/Windows, Zeitschrift FoxPro Advisor, Loseblattsammlung FoxX Professional, VFP-Entwicklerkonferenz,dfpug, foxpro, xbase, clipper, dbase, afp, foxpro, database, active-foxpro-pages, sql-server, devcon, conference, developer, relational, visual foxpro, visual extend, rad, framework


              --
              Regards

              John Timney
              ASP.NET MVP
              Microsoft Regional Director

              ".net lear" <msofficeguy@gm ail.com> wrote in message
              news:1119645477 .193466.194050@ g47g2000cwa.goo glegroups.com.. .[color=blue]
              > Thanks a lot.
              >
              > I'm just getting started with this concept, very used to procedural
              > programming.
              >
              > Isn't the cookbook just a collection of recipes? In other words,
              > doesn't it inherit from recipe to some degree?
              >
              > When you say "stored in the cookbook (persistence or data layer)", can
              > you elaborate? What does that mean?
              >
              >
              > John Timney (ASP.NET MVP) wrote:[color=green]
              >> The recipe only tells you how to cook the dish, it has no concept of
              >> where
              >> the recipe is stored in your kitchen. As it happens its stored in the
              >> cookbook (the persistence or data layer). storing the recipe has nothing
              >> to
              >> do with cooking the dish, so you should refrain from including that logic
              >> in
              >> your business layer (the recipe) - ideally the cookbook would do the
              >> deletions and inserts with the recipe being an argument passed to it as
              >> the
              >> persistence layer as inserts and deletions are something that occur to
              >> your
              >> cookbook not your recipe.
              >>
              >> --
              >> Regards
              >>
              >> John Timney
              >> ASP.NET MVP
              >> Microsoft Regional Director
              >>
              >> --
              >> Regards
              >>
              >> John Timney
              >> ASP.NET MVP
              >> Microsoft Regional Director
              >>
              >> ".net lear" <asdfasdf> wrote in message
              >> news:uufQm7MeFH A.712@TK2MSFTNG P12.phx.gbl...[color=darkred]
              >> > if I have an object, say a recipe, which is added to a database, whose
              >> > responsibility is it to add to the db? The recipe or something else?
              >> >
              >> > Let's say I want to delete a recipe? Does the recipe kill itself? Or
              >> > does
              >> > the database or something else do the removal?
              >> >
              >> > Where does the responsibility lie?
              >> >
              >> > Thanks.
              >> >
              >> >
              >> >[/color][/color]
              >[/color]


              Comment

              • .net lear

                #8
                Re: OO question beginner

                thanks a lot.


                "John Timney (ASP.NET MVP)" <timneyj@despam med.com> wrote in message
                news:OlT%23InXe FHA.3328@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                > How it inherits depends on your encapsulation, and whether there is any
                > interaction between the cookbook and the recipe. In an ideal OO scanrio[/color]
                the[color=blue]
                > recipe should be self contained, telling you only how to make the dish.[/color]
                The[color=blue]
                > cookbook knows nothing about making the dish, thus it needs to inherit[/color]
                none[color=blue]
                > of the properties of the recipe to function as a cookbook - it only needs[/color]
                to[color=blue]
                > contain recipe objects, like a namespace containing lots of different
                > classes. The classes in the namespace can be interelated by existing in[/color]
                the[color=blue]
                > namespace, but need not know anything about each other unless thats how to
                > need the objects to interact. Connected to this, the way you serve the
                > recipe (the presentation (layer)) has nothing to do with how it is stored[/color]
                in[color=blue]
                > the cookbook (persistence (layer)) or how it is cooked (business (layer))
                >
                > Mutli tiered or layered implementations perform different and self[/color]
                contained[color=blue]
                > elements of your programming logic, like your presentation layer knowing
                > about plates and cress but nothing about cooking times. Theres a very[/color]
                nice[color=blue]
                > and straingtforward explanation of multi tiered applications here that[/color]
                might[color=blue]
                > be worth taking a look at.
                >
                > http://www.dfpug.de/konf/konf_1999/g...ier/e_tier.htm
                >
                > --
                > Regards
                >
                > John Timney
                > ASP.NET MVP
                > Microsoft Regional Director
                >
                > ".net lear" <msofficeguy@gm ail.com> wrote in message
                > news:1119645477 .193466.194050@ g47g2000cwa.goo glegroups.com.. .[color=green]
                > > Thanks a lot.
                > >
                > > I'm just getting started with this concept, very used to procedural
                > > programming.
                > >
                > > Isn't the cookbook just a collection of recipes? In other words,
                > > doesn't it inherit from recipe to some degree?
                > >
                > > When you say "stored in the cookbook (persistence or data layer)", can
                > > you elaborate? What does that mean?
                > >
                > >
                > > John Timney (ASP.NET MVP) wrote:[color=darkred]
                > >> The recipe only tells you how to cook the dish, it has no concept of
                > >> where
                > >> the recipe is stored in your kitchen. As it happens its stored in the
                > >> cookbook (the persistence or data layer). storing the recipe has[/color][/color][/color]
                nothing[color=blue][color=green][color=darkred]
                > >> to
                > >> do with cooking the dish, so you should refrain from including that[/color][/color][/color]
                logic[color=blue][color=green][color=darkred]
                > >> in
                > >> your business layer (the recipe) - ideally the cookbook would do the
                > >> deletions and inserts with the recipe being an argument passed to it as
                > >> the
                > >> persistence layer as inserts and deletions are something that occur to
                > >> your
                > >> cookbook not your recipe.
                > >>
                > >> --
                > >> Regards
                > >>
                > >> John Timney
                > >> ASP.NET MVP
                > >> Microsoft Regional Director
                > >>
                > >> --
                > >> Regards
                > >>
                > >> John Timney
                > >> ASP.NET MVP
                > >> Microsoft Regional Director
                > >>
                > >> ".net lear" <asdfasdf> wrote in message
                > >> news:uufQm7MeFH A.712@TK2MSFTNG P12.phx.gbl...
                > >> > if I have an object, say a recipe, which is added to a database,[/color][/color][/color]
                whose[color=blue][color=green][color=darkred]
                > >> > responsibility is it to add to the db? The recipe or something else?
                > >> >
                > >> > Let's say I want to delete a recipe? Does the recipe kill itself? Or
                > >> > does
                > >> > the database or something else do the removal?
                > >> >
                > >> > Where does the responsibility lie?
                > >> >
                > >> > Thanks.
                > >> >
                > >> >
                > >> >[/color]
                > >[/color]
                >
                >[/color]


                Comment

                Working...