Skip to content

Instantly share code, notes, and snippets.

@darekmydlarz
Created December 14, 2017 10:20
Show Gist options
  • Save darekmydlarz/e1534442e0f1dd6379807b0fc169d1fb to your computer and use it in GitHub Desktop.
Save darekmydlarz/e1534442e0f1dd6379807b0fc169d1fb to your computer and use it in GitHub Desktop.
What the OOP is about?
// procedular programming
@Value
class IdProvider {
private final String id;
private final String email;
// getters
}
RemotePerson find(Person person) {
return remoteClient.find(new IdProvider(person.getId(), person.getEmail()));
}
// vs. oop programming
interface IdProvider {
String id();
String email();
}
RemotePerson find(Person person) {
return remoteClient.find(new PersonIdProvider(person));
}
// implementation
class PersonIdProvider implements IdProvider {
private final Person person;
PersonIdProvider(Person person) {
this.person = person;
}
public String id() {
return person.getId();
}
public String email() {
return person.getEmail();
}
}
@darekmydlarz
Copy link
Author

one could say procedular is not bad;
but procedural takes your data in an offensive way; without even asking;

on the other hand: oop is mainly about objects compositoin;
i am not taking data from you; i am just telling WHAT you are (a PersonIdProvider);
it's your job to provide me required data; if you want you can throw exception, you can do some calculations, etc;
but it is your responsibiliy; I trust you (!)

in proceduarl programming I am offensive to you; I dont trust you at all, I just want this dumb data from you, and I let you go, I don't care about you;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment