1.2.4 Programming Languages

Cards (9)

  • OOP are built around the idea of classes. A class is a template for an object and defines the state and behaviour of an object.
  • State is given by attributes, which give an object's properties.
  • Behaviour is defined by the methods associated with a class, describing the actions it can perform.
  • Classes can be used to create objects by a process called instantiation. An object is a particular instance of a class, and a class can be used to create multiple objects with the same set f attributes and methods.
  • Classes are usually associated with entities.
  • A setter is a method that sets the value of a particular attribute. In this example, 'set_reserved' would set the attribute 'Reserved' to 'True' if someone wants to reserve the book.
  • A getter is another method used in OOP which retrieves the value of a given attribute.
  • Getters & setters are used to make sure attributes cannot be directly accessed and edited by users. This property is called encapsulation, attributes are declared as private. Every class must also have a constructor method, which is called 'new'.
  • this.#variable makes it private in JavaScript