What is Object Orientation – Classes are blueprints – Classes vs. Instances



What is Object Orientation – Classes are blueprints – Classes vs. Instances

0 0


my_first_reveal_test


On Github fontcuberta / my_first_reveal_test

What is Object Orientation

What is Object Orientation

Computer programs are designed by making them out of objects that interact with one another.

Classes are blueprints

To build something we need to create some kind of blueprints to, then, pass it around to our little oompa loompas to build it.

Exercise

Create a class that represents a Car. That car should have a method to make noise that prints “Broom” to the console. Then create one car and call that method

Classes vs. Instances

The Constructor

- A special method called *initialize*

- It is executed for each instance we create

Exercise

Modify our Car class so we can have different sounds for different cars. Each car should have its own sound. Create two cars. One of the should make “Broom” and the other should make “BROOOOOOM”.

Class Variables

- Its name starts with the @@ sign

- All instances of a class share the same value for this variable

Instance methods and class methods

- By default all methods are instance methods

- We can also have methods for a class if we prepend its name with *self*. during declaration

Design

What is design in software?

What are blueprints in software

Encapsulation

- The important part of an object is the messages (methods) it exposes and the outcome they produce

- The objects are black boxes. We should not care on how the code is done but what it does.

- This is the most basic form of abstracting complexity

What is Object Orientation