Skip to content

Commit

Permalink
violates dependency inversion
Browse files Browse the repository at this point in the history
  • Loading branch information
kenziehong committed Jan 14, 2021
1 parent 19bd5d5 commit d3fb540
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Basic/Solid/MySQLConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class MySQLConnection {
public function connect() {
return 'Database connection';
}
}
9 changes: 9 additions & 0 deletions Basic/Solid/PasswordRemider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class PasswordRemider { // high-level module
private $dbConnection;

public function __construct(MySQLConnection $dbConnection) { // low-level module (1. violates denpend on abstraction, not on concretions, 2. violates the open-closed principle when database changes)
$this->dbConnection = $dbConnection;
}
}
2 changes: 2 additions & 0 deletions Basic/Solid/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ This means that every subclass or derived class should be substitutable for thei

# Interface Segregation Principle
A client should never be forced to implement an interface that it doesn’t use, or clients shouldn’t be forced to depend on methods they do not use.
# Dependency Inversion Principle
Entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions.

0 comments on commit d3fb540

Please sign in to comment.