A
A
Albert Sultangulov2019-02-19 06:54:15
Java
Albert Sultangulov, 2019-02-19 06:54:15

What does it mean to model real world objects in OOP?

"OOP programs model real world objects, so the complexity is reduced and the structure is clearer." Please explain with examples

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
luna3956, 2019-02-19
@Berht

Imagine that you need to write a program that keeps a record of private houses on some street. The key unit will be the house - an object from the real world. To describe it using program code, OOP is great for this. It has such a concept as a class, it is essentially a model / structure of an object from the real world. In our example with a house, this would be something like this class:

class House {

  string address;
  int numOfRooms;
  ...

  House(string address, int numOfRooms)
  {
    this.address = address;
    this.numOfRooms = numOfRooms;
  }

}

Now, in the program itself, in order to operate with such an object from the real world as a house, you just need to write something like this:
That is, in the variable h we now store an object / reference to an object that is a representation of an object from the real world - a five-room house, which is located at " Elm street house 13".
Or, for example, a dog (also an object from the real world) can be described by such a class:
class Dog {

  string name;
  string breed;

  Dog(string name, string breed)
  {
    this.name = name;
    this.breed = breed;
  }

}

And now, in order to "create a dog" with some name and breed in the program, it is enough to write:
These are very simplified examples, but I think they are quite suitable for you to understand how objects of the real world are modeled thanks to OOP.
PS the code itself is not Java, but just pseudo-code for clarity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question