Goodbye, Object Oriented Programming

Inheritance, the First Pillar to Fall

Banana Monkey Jungle Problem

Banana Monkey Jungle Solution

The Diamond Problem

Class PoweredDevice {
}
Class Scanner inherits from PoweredDevice {
function start() {
}
}
Class Printer inherits from PoweredDevice {
function start() {
}
}
Class Copier inherits from Scanner, Printer {
}

The Diamond Solution

Class PoweredDevice {
}
Class Scanner inherits from PoweredDevice {
function start() {
}
}
Class Printer inherits from PoweredDevice {
function start() {
}
}
Class Copier {
Scanner scanner
Printer printer
function start() {
printer.start()
}
}

The Fragile Base Class Problem

import java.util.ArrayList;

public class Array
{
private ArrayList<Object> a = new ArrayList<Object>();

public void add(Object element)
{
a.add(element);
}

public void addAll(Object elements[])
{
for (int i = 0; i < elements.length; ++i)
a.add(elements[i]); // this line is going to be changed
}
}
public class ArrayCount extends Array
{
private int count = 0;

@Override
public void add(Object element)
{
super.add(element);
++count;
}

@Override
public void addAll(Object elements[])
{
super.addAll(elements);
count += elements.length;
}
}
  public void addAll(Object elements[])
{
for (int i = 0; i < elements.length; ++i)
add(elements[i]); // this line was changed
}

The Fragile Base Class Solution

The Hierarchy Problem

The Hierarchy Solution

Document
Company
Handbook

Encapsulation, the Second Pillar to Fall

The Reference Problem

The Reference Solution

Polymorphism, the Third Pillar to Fall

Broken Promises

So then what?

--

--

--

Software Engineer and Architect, Teacher, Writer, Filmmaker, Photographer, Artist…

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Revisiting the problem of the best selection

6 Best practices to avoid common backend mistakes — Galaxy Weblinks

Microservices - Are You Ready For It?

Embedded Options in Python; Predict Basic American Option Values

Volley — HTTP For Android

My Open Source Journey

How Going Back to Coding After 10 Years Almost Crushed Me

Old technology

How I built my first open source library

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Charles Scalfani

Charles Scalfani

Software Engineer and Architect, Teacher, Writer, Filmmaker, Photographer, Artist…

More from Medium

Use git-bisect to Find Problems Fast

Object Oriented Programming w/ JavaScript| “this”, “new” & constructors

Examining the Mechanics of Singleton Pattern in C++

JavaScript — Prerequisites for Functional Programming: Function Composition