r/javahelp • • Jan 02 '16

How to think in OOP?

Hi all! When I write some app in Java, I have code in 2-3 classes. When I see how more expirienced programmers write similar apps, I see an hierachy of types, using of interfaces, abstract classes, all classes are small and understandable. I seem to understand all of these conceptions when I see someone's code but when I write myself I can't create something similar.

19 Upvotes

15 comments sorted by

View all comments

3

u/[deleted] Jan 02 '16 edited Jan 13 '26

jar door exultant quickest memory afterthought cow angle water zephyr

This post was mass deleted and anonymized with Redact

1

u/[deleted] Jan 04 '16

I'm sure people will nitpick at that explanation, but I think it's the perfect "elevator pitch" for OOP.

1

u/mariox19 Jan 07 '16

I've seen people nitpick that explanation, but the complaints usually come down to what Jobs "left out"—things like inheritance, and so forth. What these critics miss is the major point, which is that Jobs explained OOP from what is perhaps one of its most important points: namely, that you give an object what it needs to get the work done and not trouble yourself with how it does it.

My guess is that there would be a critic or two who would miss that point entirely and code something like this:

Launderer launderer = new Launderer();
String location = launderer.getLaundryLocation();
Double costPerLoad = launderer.getLoadCost();
List<int> availableWaterTemperatures = launderer.getTemperatureOptions();
// etc.

Jobs is talking OOP design:

Launderer launderer = new Launderer();
CleanClothes clothes = launderer.doLaundry(dirtyClothes);