Under review

Relations Between Objects - Dependency

manh duong 2 years ago updated by Alex Shvets 2 years ago 1

In the section "Relations Between Objects" part "Dependency", you wrote.


Dependency is the most basic and the weakest type of relations between classes.

There is a dependency between two classes if some changes to the definition of one class might result in modifications to another class.

Dependency typically occurs when you use concrete class names in your code.

For example, when specifying types in method signatures, when instantiating objects via constructor calls, etc.

You can make a dependency weaker if you make your code dependent on interfaces or abstract classes instead of concrete classes.


With the example

class Interface {

class Concrete: public Interface {

class App { // App --> Interface, App -(weaker)-> Concrete
void fun(Interface interface) { // make code dependent on interface

I understand that the App class is dependent on Interface, and dependent weaker with Concrete class.

Is it right or wrong?

Best regards,

Under review


Yes, it's all correct.