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. Mapping a real world object to OOP

Mapping a real world object to OOP

Scheduled Pinned Locked Moved C#
adobehelptutorialquestion
7 Posts 4 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.
  • S Offline
    S Offline
    sinanju
    wrote on last edited by
    #1

    how to map an object of the so called real life to programming world. Say there is a car. How can we take this to programming world. Car with wheel, engine, etc. Car can move without even doors, it's movement will be effected if one wheel is with low air pressure. etc. Here car should be an object, wheel also an object. Car has wheels, doors etc., but wheel has different impact than doors as far as motion is concerned. Can someone help me visualize this object to OOP?

    C J 2 Replies Last reply
    0
    • S sinanju

      how to map an object of the so called real life to programming world. Say there is a car. How can we take this to programming world. Car with wheel, engine, etc. Car can move without even doors, it's movement will be effected if one wheel is with low air pressure. etc. Here car should be an object, wheel also an object. Car has wheels, doors etc., but wheel has different impact than doors as far as motion is concerned. Can someone help me visualize this object to OOP?

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

      You can't, not really. Every car has some stains on the seats, are you going to bother to map those ? Chips in the paint ? Oil on the engine ? No. You choose the bits that are important to what you want to write, and you map those to classes. Getting it exactly the way it is in the real world is not the point, mapping the bits you want to interact with so they work smoothly in your program, is.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      S 1 Reply Last reply
      0
      • C Christian Graus

        You can't, not really. Every car has some stains on the seats, are you going to bother to map those ? Chips in the paint ? Oil on the engine ? No. You choose the bits that are important to what you want to write, and you map those to classes. Getting it exactly the way it is in the real world is not the point, mapping the bits you want to interact with so they work smoothly in your program, is.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        S Offline
        S Offline
        sinanju
        wrote on last edited by
        #3

        >>You can't, not really. Help me to some extent. >>Every car has some stains on the seats, are you going to bother to map those ? Yes, anything with some volume should be able to interact with the seat. There some physics rules should come handy. and so on >> Chips in the paint ? Yes, again some interaction with the environment. How environment can effect the car? >> Oil on the engine ? Yes, of course. Help me outhere as well. >> No. You choose the bits that are important to what you want to write, and you map those to classes. Getting it exactly the way it is in the real world is not the point, mapping the bits you want to interact with so they work smoothly in your program, is. 'm want to simulate the max possible.

        C 1 Reply Last reply
        0
        • S sinanju

          >>You can't, not really. Help me to some extent. >>Every car has some stains on the seats, are you going to bother to map those ? Yes, anything with some volume should be able to interact with the seat. There some physics rules should come handy. and so on >> Chips in the paint ? Yes, again some interaction with the environment. How environment can effect the car? >> Oil on the engine ? Yes, of course. Help me outhere as well. >> No. You choose the bits that are important to what you want to write, and you map those to classes. Getting it exactly the way it is in the real world is not the point, mapping the bits you want to interact with so they work smoothly in your program, is. 'm want to simulate the max possible.

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

          sinanju wrote:

          'm want to simulate the max possible.

          Why ? Are you writing a game ? Why would you care if there's oil ON the engine ( under the hood ), or chips in the paint, or stains in the seat ?

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          1 Reply Last reply
          0
          • S sinanju

            how to map an object of the so called real life to programming world. Say there is a car. How can we take this to programming world. Car with wheel, engine, etc. Car can move without even doors, it's movement will be effected if one wheel is with low air pressure. etc. Here car should be an object, wheel also an object. Car has wheels, doors etc., but wheel has different impact than doors as far as motion is concerned. Can someone help me visualize this object to OOP?

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            public class Car { private Wheel [] wheels; private Door [] doors; private SteeringWheel steeringWheel; private GearBox gearBox; private Engine engine; public Car() { wheels = new Wheel[4]; doors = new Door[4]; gearBox = new GearBox(); steeringWheel = new SteeringWheel(); engine = new TwoLitreEngine(); } public void Start() { gearBox.SetNeutral(); while(!engine.Started) { engine.EngageStarterMotor(); } engine.DisengageStarterMotor(); } } You can go on ad infinitum implementing whatever objects you want to define. The above code relies on an implementation of Wheel, Door, GearBox, and SteeringWheel. Also, a base class called Engine and an implementation of it called TwoLitreEngine is defined.

            --- How to get answers to your questions[^]

            W 1 Reply Last reply
            0
            • J J4amieC

              public class Car { private Wheel [] wheels; private Door [] doors; private SteeringWheel steeringWheel; private GearBox gearBox; private Engine engine; public Car() { wheels = new Wheel[4]; doors = new Door[4]; gearBox = new GearBox(); steeringWheel = new SteeringWheel(); engine = new TwoLitreEngine(); } public void Start() { gearBox.SetNeutral(); while(!engine.Started) { engine.EngageStarterMotor(); } engine.DisengageStarterMotor(); } } You can go on ad infinitum implementing whatever objects you want to define. The above code relies on an implementation of Wheel, Door, GearBox, and SteeringWheel. Also, a base class called Engine and an implementation of it called TwoLitreEngine is defined.

              --- How to get answers to your questions[^]

              W Offline
              W Offline
              wheelerbarry
              wrote on last edited by
              #6

              Car a is a very large object to map. This class is a decent basic overview, but due to the massive variations between types of car, you could consider making it abstract and defining specific types of car. This implementation assumes that a car will have 4 wheels (some had 3), and 4 doors (some have 2), and does the book count as a door? Manual or Auto gearbox, etc. e.g. public class VauxhallCorsa : public Car { public VauxhallCorsa() { wheels = new Wheel[4]; doors = new Door[3]; gearBox = new ManualGearBox(); steeringWheel = new SteeringWheel(); engine = new OneLitreEngine(); } }

              J 1 Reply Last reply
              0
              • W wheelerbarry

                Car a is a very large object to map. This class is a decent basic overview, but due to the massive variations between types of car, you could consider making it abstract and defining specific types of car. This implementation assumes that a car will have 4 wheels (some had 3), and 4 doors (some have 2), and does the book count as a door? Manual or Auto gearbox, etc. e.g. public class VauxhallCorsa : public Car { public VauxhallCorsa() { wheels = new Wheel[4]; doors = new Door[3]; gearBox = new ManualGearBox(); steeringWheel = new SteeringWheel(); engine = new OneLitreEngine(); } }

                J Offline
                J Offline
                J4amieC
                wrote on last edited by
                #7

                wheelerbarry wrote:

                This class is a decent basic overview, but due to the massive variations between types of car, you could consider making it abstract and defining specific types of car.

                Considering the OP isnt even proficient in defining objects yet, I tried to stear clear of the obvious abstractions. Of course, the base class should be called Vehicle allowing definition of a Boat (no wheels, still with engine), Bycycle (2 wheels, no engine/gearbox) etc etc etc. My answer was simply to give a basic layout of a class, which i think is what the OP asked for!

                --- How to get answers to your questions[^]

                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