DEV Community

Cover image for Unlocking the Power of Objects in Object-Oriented Programming (OOP)
M ZUNAIR TARIQ
M ZUNAIR TARIQ

Posted on

Unlocking the Power of Objects in Object-Oriented Programming (OOP)

Objects serve as the lively foundations of software engineering, encapsulating real-world items and functionalities within code. These dynamic entities, identical to players on a digital stage, play an essential role in modern programming, encapsulating attributes and behaviors within instances of classes. Join us on a tour through the immersive world of OOP's objects as we examine their significance, dive into their creation, and observe how important they are in developing powerful and adaptive software applications.

Objects

In Object-Oriented Programming (OOP), objects are instances of classes that contain data (attributes or properties) and behavior (methods or functions). They represent real-world entities, concepts, or instances in a program.

Here are some crucial points regarding objects:

  • Instances of Classes: Objects are formed based on the blueprint or template defined by a class. Each object created from a class is an independent instance with its own set of properties and behaviors defined by that class.

  • Properties: Objects contain attributes or properties that define their state. These properties store data relating to the object.
    For example, a Car object might have properties like brand, model, color, etc.

  • Behaviors or Methods: Objects can perform actions or behaviors using methods. Methods are functions associated with objects that allow them to interact with their own data or perform certain tasks.
    For instance, a Car object might have methods like startEngine(), accelerate(), stop(), etc.

//Object Example

class Car
{
    public string Brand { get; set; }
    public string Model { get; set; }

    public void DisplayInfo()
    {
        Console.WriteLine($"Car Information: {Brand} {Model}");
    }
}

class Program
{
    static void Main()
    {
        // Creating an instance (object) of the Car class
        Car myCar = new Car();

        // Setting properties of the Car object
        myCar.Brand = "Toyota";
        myCar.Model = "Corolla";

        // Accessing a method of the Car object
        myCar.DisplayInfo(); // Outputs: Car Information: Toyota Corolla
    }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (6)

Collapse
 
abranasays profile image
Abdul Basit Rana

Very Good Explanination

Collapse
 
mzunairtariq profile image
M ZUNAIR TARIQ

thanks for your kind words🙌

Collapse
 
efpage profile image
Eckehard • Edited

Try out DML, a Javascript library that enables an object oriented design pattern for web applications, including event based reactivity. It´s fun to use.

Collapse
 
mzunairtariq profile image
M ZUNAIR TARIQ

sounds interesting, will try it shortly 🙌

Collapse
 
efpage profile image
Eckehard

There are some more examples on dev.to if you search for "DML".

If you are looking for a larger project, take a closer look to the homepage code. The page is currently not compressed, so you can check out the source codes (next version will use vite). There are only two HTML-files dml.efpage.de/DML_homepage/index.html and dml.efpage.de/DML_homepage/index.html that generate all pages, content is delivered by markdowns.

I suppose, this is a very unconventional way to build web pages, but as you will see, it is pretty fast.

Thread Thread
 
mzunairtariq profile image
M ZUNAIR TARIQ

Acknowledged 💫