All original content is created in Ukrainian. Not all content has been translated yet. Some posts may only be available in Ukrainian.Learn more

What is OOP (object-oriented programming)?

This content has been automatically translated from Ukrainian.
Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes to organize code. The main ideas of OOP are based on the attempt to model the real world in programming code, using the concepts of objects that have properties (attributes) and behavior (methods).

Advantages of OOP

Modularity: Objects allow to encapsulate functionality and state, making the code more modular and easier to understand.
Inheritance: The ability to create a new class based on an existing one allows for code reuse and reduces duplication.
Polymorphism: The ability to use the same interface for different classes allows for extending functionality without modifying existing code.

Languages that Support OOP Paradigm

Java, C++, C#, Python, Ruby, Swift, Objective-C, Kotlin, PHP, JavaScript, Scala, Dart, Smalltalk, Eiffel, Simula, Go, Perl, Rust, Lua, Groovy, Haskell, Ada, Groovy, Delphi/Object Pascal, Fortran, R, ABAP, TypeScript, ActionScript, ColdFusion, PowerBuilder, Prolog, Visual Basic (VB.NET), F#, COBOL, PL/SQL, Io, Erlang, Lua, APL and many others.
Many languages can support multiple programming paradigms simultaneously. So this list is actually larger.

OOP Basics

Classes - are templates or blueprints for creating objects. A class defines the properties (attributes) and methods (functions) that an object will have.
An Object - is a specific instance of a class created using the class constructor. Each object has its own state (attribute values) and behavior (response to method calls).
Encapsulation in OOP means combining data and methods that operate on that data within a single object or class. Encapsulation allows for hiding the internal implementation and restricts access to certain components from the outside.
Inheritance allows for creating a new class based on an existing (parent) class, inheriting its properties and methods. This promotes the use of existing code and extends its functionality.
Polymorphism means the ability of objects of different classes to invoke the same method or function with the same name. This makes programs more flexible and generalized.

Example of Creating a Class and Object in Ruby

class Person
  attr_accessor :name, :age

  def initialize(name, age)
    @name = name
    @age = age
  end

  def introduce
    puts "Hi, I'm #{@name} and I'm #{@age} years old."
  end
end

# Creating an object of the Person class
person = Person.new("John", 25)

# Calling the object's method
person.introduce

This post doesn't have any additions from the author yet.

24 Jul 12:01

What is "Vulkan Shader Processing" in Steam?

meme code
meme code@memecode
24 Jul 12:17

How to make Counter-Strike: GO fullscreen in Ubuntu without launching the game?

meme code
meme code@memecode
20 Nov 19:35

How to recover a deleted file (Trix) that was stored on Amazon S3?

meme code
meme code@memecode
29 Nov 08:47

What is the difference between var and let in Javascript?

meme code
meme code@memecode
07 Dec 07:42

What is encapsulation in OOP?

meme code
meme code@memecode
07 Dec 08:13

Visibility control in Ruby (public, private, and protected)

meme code
meme code@memecode
09 Dec 12:00

What is inheritance in Ruby? Examples of bad and good inheritance.

meme code
meme code@memecode
09 Dec 12:15

What is best practice in programming?

meme code
meme code@memecode
09 Dec 12:21

What is polymorphism? An example of using polymorphism in Ruby.

meme code
meme code@memecode
09 Dec 12:46

Що таке патерн/шаблон проєктування?

meme code
meme code@memecode
10 Dec 14:03

What is a design pattern in programming?

meme code
meme code@memecode
10 Dec 14:18

What is a client and a server? What is the interaction mechanism between the client and the server?

meme code
meme code@memecode