DEV Community

Cover image for OOP Concepts: What's Your Biggest Challenge?
Max Zhuk
Max Zhuk

Posted on

6 1 2 1

OOP Concepts: What's Your Biggest Challenge?

Hey, fellow developers!🧑🏼‍💻

I'm currently working on a book about Object-Oriented Programming in PHP and TypeScript, and I'm curious about your experiences with OOP.

As developers, we all have those concepts that make us scratch our heads from time to time. So, I want to ask: Which OOP concept do you find most challenging to master?

  • Inheritance
  • Polymorphism
  • Encapsulation
  • Abstraction

Drop your answer in the comments, and let's discuss why! Your insights might even help shape some explanations in my upcoming book.

To kick things off, here's a quick PHP 8 snippet showcasing polymorphism:

interface Logger
{
    public function log(string $message): void;
}

class ConsoleLogger implements Logger
{
    public function log(string $message): void
    {
        echo "Console: $message\n";
    }
}

class FileLogger implements Logger
{
    public function log(string $message): void
    {
        file_put_contents('log.txt', "File: $message\n", FILE_APPEND);
    }
}

function doSomething(Logger $logger)
{
    $logger->log("Operation completed");
}

doSomething(new ConsoleLogger());
doSomething(new FileLogger());
Enter fullscreen mode Exit fullscreen mode

This example demonstrates how different classes can implement the same interface, allowing for flexible and extensible code.

What's your take on polymorphism? Love it? Hate it? Share your thoughts!


Photo by rivage on Unsplash

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (2)

Collapse
 
efpage profile image
Eckehard

I just wrote a post about the "S" in the SOLID principle which is about the challenges of inheritance. Maybe you can find some inspiration there.

Collapse
 
mukesh_singhania_1992 profile image
Mukesh Singhania

Working on abstraction fundamentals

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video