Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Software Architecture Journey - Teil 1 - Archit...

Software Architecture Journey - Teil 1 - Architektur und Designprinzipien

Vor einiger Zeit habe ich das Buch "Clean Architecture" von Robert C. Martin gelesen. Dieses Buch hat mich inhaltlich sehr begeistert und ich möchte meine Erfahrungen und mein erlangtes Wissen gerne an euch weitergeben.

Im ersten Teil dieser Reihe geht es um "Was ist Softwarearchitektur, wie beeinflussen Architekturentscheidungen mein Projekt und welche grundlegenden Designprinzipien gibt es?“

Avatar for Christian Bonzelet

Christian Bonzelet

February 13, 2019

Other Decks in Programming

Transcript

  1. 3

  2. 9

  3. 10 “Ein planlos strukturierter, sich ständig ausbreitender, schlampiger, mit Panzertape

    und Kabelbinder zusammengehaltener Spaghetti-Code Dschungel”
  4. “Man ist nur dann schnell, wenn man die Dinge richtig

    angeht.” Robert C. Martin - Clean Architecture - Seite 10 11
  5. Eisenhower's Matrix “I have two kind of problems, the urgent

    and the important. The urgent are not important, and the important are never urgent” 1 2 3 4 !!! Architektur !!! 17
  6. Objektorientierte Programmierung “The combination of data and function” “A way

    to model the real world” “Encapsulation, inheritance and polymorphism” 20
  7. 26

  8. 27 public class UserService { private Logger logger = Logger.getLogger("com.training.core.srp.UserService");

    public void createUser(User user) throws DBConnectionException { Connection connection = null; DataSource dataSource = null; try { InitialContext initialContext = new InitialContext(); dataSource = (DataSource) initialContext.lookup("jdbc/tempDB"); } catch (NamingException e) { // Handle the exception using Logger } try { connection = dataSource.getConnection(); } catch (SQLException e) { logger.log(Level.SEVERE, "Issue connecting with database: " + e.getMessage()); throw new DBConnectionException(e.getMessage()); } String sql = "INSERT INTO User (USER_ID, USERNAME) VALUES (?,?)"; try { PreparedStatement pstmt = connection.prepareStatement(sql); pstmt.setString(1, "some-user-id-123456"); pstmt.setString(2, "Ajitesh"); // execute insert SQL stetement pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { logger.log(Level.WARNING, "Issue with saving the data: " + e.getMessage()); } } }
  9. 28 public class UserService { private UserDAO userDAO; public void

    createUser(User user) throws UserCreationException { userDAO.save(user); } public UserDAO getUserDAO() { return userDAO; } public void setUserDAO(UserDAO userDAO) { this.userDAO = userDAO; } }
  10. OCP - The Open-Closed Principle “A software artifact should be

    open for extension but closed for modification” 30
  11. 31

  12. 33 public class AreaCalculator { public double Area(Rectangle[] shapes) {

    double area = 0; for(Rectangle shape : shapes) { area += shape.getWidth() * shape.getHeight(); } return area; } }
  13. 34 for(Object shape : shapes) { if (shape instanceof Rectangle)

    { Rectangle rectangle = (Rectangle) shape; area += rectangle.getWidth() *rectangle.getHeight(); } else { Circle circle = (Circle) shape; area += circle.getRadius() * circle.getRadius() * Math.PI; } }
  14. 36 Wenn Komponente A von Änderungen in Komponente B geschützt

    werden soll: Calculator Component (A) AreaCalculator Shape Component (B) Circle Rectangle Calculator Component (A) <<abstract>> Shape AreaCalculator Shape Component (B) Circle Rectangle
  15. LSP - The Liskov Substitution Principle “If for each object

    o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T” 38
  16. 39

  17. Barbara Jane Huberman Liskov (* 7. November 1939 in Los

    Angeles) ist eine amerikanische Informatikerin. Sie ist als Professorin für Elektrotechnik und Informatik am MIT tätig. [...] Barbara Liskov leitete zahlreiche bedeutende Projekte, darunter den Entwurf und die Implementierung der Programmiersprachen CLU und Argus sowie des objektorientierten Datenbankmanagementsystems Thor. 40
  18. ISP - The Interface Segregation Principle “No client should be

    forced to depend on methods it does not use.” 43
  19. 44

  20. 45

  21. 46

  22. 47

  23. DIP - The Dependency Inversion Principle “The DIP tells us

    that the most flexible systems are those in which source code dependencies refer only to abstractions, not concretions.” 49
  24. 50

  25. Erfolgsfaktoren für Stabilität 1. Referenziere keine unbeständigen, konkreten Klassen 2.

    Leite nicht von unbeständigen, konkreten Klassen ab 3. Überschreibe keine konkreten Methoden 52
  26. 55

  27. 56

  28. public class Application { private static ServiceFactory = new ConcreteServiceFactory();

    public static void main() { Service myService = factory.createService(); // do somethin stupid } } Verstoßen wir hier nicht auch gegen das DIP? 58
  29. 60