How many object oriented languages are there




















Object-oriented programming OOP languages are everywhere we look. Many of the most widely used coding languages that make up the computing world today are object-oriented. In fact, many computer programs and much of the content on the web is built on high-level, object-oriented languages. Understanding how object-oriented languages work and why they are useful is important for almost every career in computing.

A programming language is a set of rules and procedures that allow programmers to give computers a set of instructions to execute. Every programming language has its own syntax, which, once learned, allows you to tell a computer what tasks it should perform.

Think about it this way. English is a language that allows you to communicate with English speakers. When you know the basic rules of English, you can talk with anyone else who understands those same rules. Computers are powerful machines. With a computer, we can calculate numbers extremely quickly, and we are able to produce amazing programs for many applications. However, to take advantage of this power, we need to communicate with the computer is something less painful than manually typing ones and zeros.

However, the further removed we get from machine code the more abstract and specialized languages become in handling data. This is why we have so many languages; no one language is perfect, and they all have different and overlapping applications. To this note, programming languages are often separated by their programming paradigm.

A programming paradigm is one way of looking at and accessing data. The two primary paradigms are Object-Oriented and Functional , although there are many more including some that are underlying principles for the above. Get matched to a bootcamp today. The average bootcamp grad spent less than six months in career transition, from starting a bootcamp to finding their first job.

Object-Oriented programming is built around objects, which are data structures that contain both data properties or attributes and code procedures or methods. The objects in object-oriented software design can be thought of like actual objects. Think of an object, like a watch. That watch has properties. But that object also does things. It displays the time, and it also can affect itself by spinning gears to change the position of its hands.

Assuming the watch is well-built it will reliably tell time, without us having to interfere with its inner workings. Object-oriented languages have objects similar to real-world objects. They can have properties and functions. They also tend to follow a certain set of principles. Object-oriented languages come with four principles. These four principles are common properties that define them and make them significantly more efficient. Some people call them the four pillars of object-oriented programming.

They support programming using the classes and objects paradigm. Object-oriented code is extremely modular by design. Because of polymorphism and abstraction, you can make one function that can be used over and over again. This saves time, reduces complexity, saves space, and makes coding a lighter load on our fingers.

There is enough groundwork for parts of the program to be developed separately from each other and still function under object-oriented principles. This makes concurrent development much easier for larger development teams.

Because most, if not all, of our code is in one place, being called and reused, that code is much easier to maintain. Instead of having to individually fix a hundred different instances where a function is called, we can fix the one modular and polymorphic function.

While most languages have some security, object-oriented languages are convenient because security is built-in with encapsulation.

Other methods and classes cannot access private data by default, and programs written in OOP languages are more secure for it. Object-oriented programming languages break down an application into objects and classes.

This is beneficial because it gives your application a more modular structure. How would you design simple, reusable software to model the dogs? With hundreds of dogs, it would be inefficient to write unique code for each dog. Below we see what that might look like with objects rufus and fluffy. As you can see above, there is a lot of duplicated code between both objects.

The age function appears in each object. Since we want the same information for each dog, we can use objects and classes instead. Grouping related information together to form a class structure makes the code shorter and easier to maintain. Create a parent class for all dogs as a blueprint of information and behaviors methods that all dogs will have, regardless of type. Create child classes to represent different subcategories of dog under the generic parent blueprint. Add unique attributes and behaviors to the child classes to represent differences.

The diagram below represents how to design an OOP program: grouping the related data and behaviors together to form a simple template then creating subgroups for specialized data and behavior. The Dog class is a generic template, containing only the structure about data and behaviors common to all dogs. These have the inherited behaviors of Dog bark but also behavior unique to dogs of that subtype. Finally,we create objects of the HerdingDog type to represent the individual dogs Fluffy and Maisel.

We can also create objects like Rufus that fit under the broad class of Dog but do not fit under either HerdingDog or TrackingDog. In a nutshell, classes are essentially user defined data types. Classes are where we create a blueprint for the structure of methods and attributes. Individual objects are instantiated, or created from this blueprint.

Classes contain fields for attributes, and methods for behaviors. Remember the class is a template for modeling a dog, and an object is instantiated from the class representing an individual real world thing.

Enjoying the article? Scroll down to sign up for our free, bi-monthly newsletter. Of course OOP includes objects!

Objects are instances of classes created with specific data, for example in the code snippet below Rufus is an instance of the Dog class. In JavaScript objects are a type of variable.

This may cause confusion, because objects can also be declared without a class template in JavaScript, as shown at the beginning. Objects have states and behaviors. Behaviors are methods, the object can undertake. Attributes are the information that is stored. Attributes are defined in the Class template. When objects are instantiated individual objects contain data stored in the Attributes field. For example, a puppy and a dog might be treated differently at pet camp. The birthday could define the state of an object, and allow the software to handle dogs of different ages differently.

Methods represent behaviors. When individual objects are instantiated, these objects can call the methods defined in the class. In the code snippet below, the bark method is defined in Dog class, and the bark method is called on the Rufus object.

Methods often modify, update or delete data. The updateAttendance method adds a day the Dog attended the pet sitting camp. The attendance attribute is important to keep track of for billing Owners at the end of the month.

Methods are how programmers promote reusability, and keep functionality encapsulated inside an object. This reusability is a great benefit when debugging.

Learn OOP without scrubbing through videos or documentation. Inheritance allows classes to inherit features of other classes. Put another way, parent classes extend attributes and behaviors to child classes.

Inheritance supports reusability. If basic attributes and behaviors are defined in a parent class, child classes can be created extending the functionality of the parent class, and adding additional attributes and behaviors. For example, herding dogs have the unique ability to herd animals. In other words, all herding dogs are dogs, but not all dogs are herding dogs. We represent this difference by creating a child class HerdingDog from the parent class Dog , and then add the unique herd behavior.

The benefits of inheritance are programs can create a generic parent class, and then create more specific child classes as needed. This simplifies overall programming, because instead of recreating the structure of the Dog class multiple times, child classes automatically gain access to functionalities within their parent class. In the following code snippet, child class HerdingDog inherits the method bark from the parent class Dog , and the child class adds an additional method, herd.

Notice that the HerdingDog class does not have a copy of the bark method, it inherits the bark method defined in the parent Dog class. When the code calls fluffy. Note: Parent class is also known as super class, or base class. Child class can also be called derived class, or extended class. In JavaScript, inheritance is also known as prototyping. A prototype object acts as a template for another object to inherit properties and behaviors from. There can be multiple prototype object templates, creating a prototype chain.

Inheritance is from parent to child. In our example all three dogs can bark, but only Maisel and Fluffy can herd. The herd method is defined in the child HerdingDog class, so the two objects, Maisel and Fluffy , instantiated from the HerdingDog class have access to the herd method. Rufus is an object instantiated from the parent class Dog , so Rufus only has access to the bark method. Encapsulation means containing all important information inside an object , and only exposing selected information to the outside world.

Attributes and behaviors are defined by code inside the class template. Then, when an object is instantiated from the class, the data and methods are encapsulated in that object. Encapsulation hides the internal software code implementation inside a class, and hides internal data of inside objects.

The information the car shares with the outside world, using blinkers to indicate turns, are public interfaces. In contrast, the engine is hidden under the hood. However, exposing internal, private data like the engine temperature, would just confuse other drivers. Encapsulation adds security. This adds a layer of security, where the developer chooses what data can be seen on an object by exposing that data through public methods in the class definition.

Within classes, most programming languages have public, protected, and private sections. Public is the limited selection of methods available to the outside world, or other classes within the program. Protected is only accessible to child classes.

Private code can only be accessed from within that class. Note: JavaScript has private and protected properties and methods. Consider the getAge method in our example code, the calculation details are hidden inside the Dog class. This allows us to hide important information that should not be changed from both phishing and the more likely scenario of other developers mistakenly changing important data.

Encapsulation adds security to code and makes it easier to collaborate with external developers. Instead, developers create public methods that allow other developers to call methods on an object.

Ideally, these public methods come with documentation for the external developers. Abstraction means that the user interacts with only selected attributes and methods of an object. Abstraction uses simplified, high level tools, to access a complex object.



0コメント

  • 1000 / 1000