6. Principios SOLID

Martin, Robert C. (2000). "Design Principles and Design Patterns"

Single Responsibility Principle

Every element should do exactly one thing

function Users() {
  const [users, setUsers] = useState([]);

  useEffect(() => {
    fetch("https://jsonplaceholder.typicode.com/users", { method: "GET" })
      .then((response) => response.json())
      .then(setUsers);
  }, []);

  return (
    <section>
      <h1>Users: </h1>
      <ul>
        {users.map((user) => (
          <li>{user.username}</li>
        ))}
      </ul>
    </section>
  );
}

Open/Close Principle

You should be able to add functionality to some module, without modifying its existing source code

Composición >>> Herencia

Substitution Principle (Liskov)

Cualquier objeto se tiene que poder sustituir por un objeto que sea un subconjunto

Interface Segregation Principle

No fuerces cumplir interfaces que no se usen.

Dependency Inversion Principle

Interacciona con los detalles usando abstracciones

Last updated