Initiation into the object-oriented paradigm.
The programming paradigms are a theory that provides us with a basis and standardized model to solve problems with our code.
Object Oriented Programming (OOP) helps us analyze and understand all these problems to solve them in the most sustainable way in the future. Java emerged with this paradigm and is one of the languages that largely defines the direction that the POO takes.
Class and Objects
The concept of class is the first thing that distinguishes an object-oriented language from other non-object oriented languages such as C or Pascal. A class defines a new type of data. Once the data type is defined, it will be used to create or instantiate objects of that type.
When we have a problem the first thing we do is to identify Objects. The fundamental element of the POO is, as its name indicates, the Object. We can define an object as a complex set of data and programs that have structure and is part of an organization. In this case the data structures and the algorithms used to manipulate them are encapsulated in a common idea called object.
These objects can be physical or conceptual for example:
The classes with the model on which our object will be built. A class is the description of a family of objects that have the same structure (attributes) and the same behavior (methods), this information serves as a template to build many objects.
Properties and Methods
Previously we saw the concept of object, such objects can take different types of variables and data. We defined it as a kind of model with which we represent a thing or a concept. These data we use to define a behavior or characteristic of an object are called Properties and Methods.
The properties, which can also be called attributes, will always be defined as nouns. For example, in a car, they could be the make, model, color, number of doors, etc. If you think about it, you will surely come up with many. They are the same as the common variables, except for the nexus with the object. The properties of an object define its characteristics.
A method is an abstraction of an operation that can be done or performed with an object. A class can declare any number of methods that perform a variety of operations on objects. Following the example used in the vehicle properties, it can have several behaviors such as: start, stop, brake, etc. The behavior of a class is defined by creating methods. A method must contain the return type and name of the method (it is recommended that this is always in verb form).