Knajjd
Commander
★★
- Joined
- Sep 2, 2021
- Posts
- 3,125
- Online time
- 9h 44m
As we know, these are the Dark Times and the War Times on the path to nowhere but this doesn't mean we can't understand basic OO concepts a little better when we copy and pasta our code. In return for learning about the Blackpill, NoFap and NoPorn I want to say thank you and I hope this series of tips will be of some use to someone.
The real world has objects and the real world has relationships between these objects. If our code mirrors the real world then the code is easier to understand and maintain (bug fix and add features). Such was the promise of OO. As we all know most code is so unreadable programmers are prone to mild psychosis but here is an explanation of OO relationships.
1. HasA - an aeroplane HasA wing. Models a tightly coupled relationship. An aeroplane does not exist without a wing.
class Aeroplane {
Wing wing = new Wing(); # This is an instance variable.
method1();
method2();
}
2. UsesA - A person UsesA hat. Models a loosely coupled relation. If a person loses his hat, the person remains.
class Person {
method1(Hat hat) { # The hat reference is passed as an argument to the tip method.
hat.tip();
}
3. IsA - A foid is a robot.
class Foid extends Robot { # Prefer HasA relationships over IsA
}
4. LikeA - A lamp behaves like a switch
class Lamp interface Switch {
onLamp();
}
The real world has objects and the real world has relationships between these objects. If our code mirrors the real world then the code is easier to understand and maintain (bug fix and add features). Such was the promise of OO. As we all know most code is so unreadable programmers are prone to mild psychosis but here is an explanation of OO relationships.
1. HasA - an aeroplane HasA wing. Models a tightly coupled relationship. An aeroplane does not exist without a wing.
class Aeroplane {
Wing wing = new Wing(); # This is an instance variable.
method1();
method2();
}
2. UsesA - A person UsesA hat. Models a loosely coupled relation. If a person loses his hat, the person remains.
class Person {
method1(Hat hat) { # The hat reference is passed as an argument to the tip method.
hat.tip();
}
3. IsA - A foid is a robot.
class Foid extends Robot { # Prefer HasA relationships over IsA
}
4. LikeA - A lamp behaves like a switch
class Lamp interface Switch {
onLamp();
}





