For example, cats and dogs are both pets. TInheritance allows objects to receive (or inherit) the attributes and behavior of other objects, while still allowing them to define some unique characteristics. In order to be considered object-oriented, a language must implement the four major principles of OOP: However, object-oriented programming is not just about objects. Instead of having to define the variables and functions for each separate dog, you can just create a Dog class, and then create as many instances of the class as you need. Imagine writing a program for a pet shop. The main benefit that OOP provides is reusability. In this example, “Dog” is the name of the class, while “name” and “breed” are the attributes (what is known about the dog), and “drinkWater”, “eatFood”, and “wagTail” are the operations (what a dog can do in Java these are called methods). For example, in Java, a very simple class for a dog would look like this: A class usually consists of a name, a set of attributes, and a set of operations. Think of a class as a blueprint of a type of object. However, if each object had to be created individually, this approach would not bring much value, which is why in object-oriented languages, objects are organized into classes. An object defines the types of data that is known about it, and the various actions that it can perform. For example, in a program that simulates a zoo, objects would represent the different types of animals. An object in a program is meant to be a representation of a real-world object. As the name suggests, OOP is based on the idea of using objects. The concept of object-oriented programming emerged in the early 1970s as an alternative to procedural programming. This was a solid approach, but in larger programs it tended to create code that was difficult to understand and maintain. The procedural philosophy encouraged the separation of the data from the functionality of the program. These instructions would be executed one by one in order, while occasionally calling sub-routines along the way. Before object-oriented programming (OOP) gained momentum, the dominating software design methodology was procedural programming, which is, essentially, a series of instructions for the computer. Understanding Object-Oriented Programmingīecause Java is object-oriented, no discussion about the language can be complete without explaining what this concept means.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |