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. C#
  4. OOP Question

OOP Question

Scheduled Pinned Locked Moved C#
questiontutorialdiscussion
6 Posts 3 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.
  • M Offline
    M Offline
    MarkPhB
    wrote on last edited by
    #1

    Hi i had a discussion with my friend about OOP and now i want to ask some of you. The question is: Knows a file how it can be printed or knows a printer how it can print a file ? or Knows a car how it can be repaired or knows a car repair shop how it can repair a car? or Knows a clothes how it can be washed or knows a washmaschine how it can wash a clothes or generally when have a class a specific ability on its own and when have only another class a specific ability and need another class to do it according to a example above: File.Print( ) or Printer.Print( File ) ? Car.Repair( ) or CarRepairShop.Repair( Car ) ? Clothes.Wash( ) or WashMaschine.Wash( Clothes ) ?

    L C 2 Replies Last reply
    0
    • M MarkPhB

      Hi i had a discussion with my friend about OOP and now i want to ask some of you. The question is: Knows a file how it can be printed or knows a printer how it can print a file ? or Knows a car how it can be repaired or knows a car repair shop how it can repair a car? or Knows a clothes how it can be washed or knows a washmaschine how it can wash a clothes or generally when have a class a specific ability on its own and when have only another class a specific ability and need another class to do it according to a example above: File.Print( ) or Printer.Print( File ) ? Car.Repair( ) or CarRepairShop.Repair( Car ) ? Clothes.Wash( ) or WashMaschine.Wash( Clothes ) ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      MarkPhB wrote:

      File.Print( ) or Printer.Print( File ) ? Car.Repair( ) or CarRepairShop.Repair( Car ) ? Clothes.Wash( ) or WashMaschine.Wash( Clothes ) ?

      My opinion: - neither, usually a printer doesn't care about the document being sent to him, you'd have to convert any object (file, bitmap, text) to a format the printer can actually print (raw bitmap e.g.) - CarRepairShop.Repair( Car ) - WashMaschine.Wash( Clothes ) Objects like files, cars, clothes etc. have some properties on their own, but they usually don't have any abilities. A car probably doesn't know how to repair itself, but due to some given properties it may know how it should be accelerated, so Car.Accelerate() might be okay in some circumstances. regards

      M 1 Reply Last reply
      0
      • L Lost User

        MarkPhB wrote:

        File.Print( ) or Printer.Print( File ) ? Car.Repair( ) or CarRepairShop.Repair( Car ) ? Clothes.Wash( ) or WashMaschine.Wash( Clothes ) ?

        My opinion: - neither, usually a printer doesn't care about the document being sent to him, you'd have to convert any object (file, bitmap, text) to a format the printer can actually print (raw bitmap e.g.) - CarRepairShop.Repair( Car ) - WashMaschine.Wash( Clothes ) Objects like files, cars, clothes etc. have some properties on their own, but they usually don't have any abilities. A car probably doesn't know how to repair itself, but due to some given properties it may know how it should be accelerated, so Car.Accelerate() might be okay in some circumstances. regards

        M Offline
        M Offline
        MarkPhB
        wrote on last edited by
        #3

        yea thats my opinion too but my friend say: "Only the class knows what it can be done with it" for his example: "An object knows how it can be saved in a database". So he means: Object.Save() and not Database.Save( Object )

        L 1 Reply Last reply
        0
        • M MarkPhB

          yea thats my opinion too but my friend say: "Only the class knows what it can be done with it" for his example: "An object knows how it can be saved in a database". So he means: Object.Save() and not Database.Save( Object )

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Then you, me and the .NET framework disagree with your friend ;) Object.Save() makes no sense because where should the object save itself to? A database connection, a file system, over network? The object doesn't know about either of the available streams. Also, saving an object depends on the place being stored to. For a database it would be a SQLConnection, for the hard disk it would be a FileStream, for network a NetworkStream. So only the streams themselves know how to execute the proper Save() operation.

          M 1 Reply Last reply
          0
          • L Lost User

            Then you, me and the .NET framework disagree with your friend ;) Object.Save() makes no sense because where should the object save itself to? A database connection, a file system, over network? The object doesn't know about either of the available streams. Also, saving an object depends on the place being stored to. For a database it would be a SQLConnection, for the hard disk it would be a FileStream, for network a NetworkStream. So only the streams themselves know how to execute the proper Save() operation.

            M Offline
            M Offline
            MarkPhB
            wrote on last edited by
            #5

            Thx, i knew i was right =)

            1 Reply Last reply
            0
            • M MarkPhB

              Hi i had a discussion with my friend about OOP and now i want to ask some of you. The question is: Knows a file how it can be printed or knows a printer how it can print a file ? or Knows a car how it can be repaired or knows a car repair shop how it can repair a car? or Knows a clothes how it can be washed or knows a washmaschine how it can wash a clothes or generally when have a class a specific ability on its own and when have only another class a specific ability and need another class to do it according to a example above: File.Print( ) or Printer.Print( File ) ? Car.Repair( ) or CarRepairShop.Repair( Car ) ? Clothes.Wash( ) or WashMaschine.Wash( Clothes ) ?

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Your friend's ideas are not really OOP, because he wants to create monolithic classes that know how to do every aspect of any operation that involves them.

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              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