image

Acesse bootcamps ilimitados e +650 cursos pra sempre

60
%OFF
Article image
Jefferson Silva
Jefferson Silva26/02/2024 21:57
Compartilhe

S.O.L.I.D. Pocket Guide: How to write Clean Architecture

  • #Java
  • #Clean Architecture

In years 1997, I used first time a program language called Pascal (compiler + language called Turbo Pascal) in my technician course of data processing, with one machine that only who did have more than thirty minimum salary could buying, on other hand, this machine was powered with HD 3.1 GB, 16MB ram, Intel Pentium processor 486 DX2 of 66 Mhz. My teacher was Marcello Niek (at the moment he is a medical doctor) and in all lessons at the laboratory everyone had to install the Pascal Turbo 6/7 version where we learned about sequence, decision and iterations using it. Years farther, all it would help me to migrate to Delphi Language(including studies about Object Oriented Programming) and achieve one certified about this knowledge. About Software Architecture, what is Clean Architecture?

Robert C. Martin said (in your book Clean Architecture: A Craftsman's Guide to Software Structure and Design) that a machine reasonable in nowadays is 10^22 more potent than the machines of 60 years illustrated with coins inside wallet or bag at orders of magnitude, which is represented by atomic structure how equals the number of electrons over there, obviously this related by useful hardware powered with MacBook Intel i7 2.8 Ghz each core of 4 16GB ram and 1TB hd.

If one programmer of half a century past, has been transported to programming in the MacBook, using Java and IntelliJ and other technologies in the market this technician would deliver good codes using that? your patterns would be conforming with all ours frequently used nowadays? efficient code, clean code? reusable code?

The answer is true because not exist nothing new exists using Java that old languages such as FORTRAN, Basic, Pascal and others, this is, the immutable code and the principles to order and mount block of build of programs universal which haven’t changed. Each rule of ordering also is immutable and universal. Basically, the S.O.L.I.D. principles says how organizing the functions and data structures in class and how these classes should be interconnected.

In brief, SR (Single Responsibility) one corollary of law Conway (about more this law in the book DevOps Handbook. How to Achieve Agility, Reliability and Security in Technological Organizations) is the structure that the software has been influenced by the social structure of organizations that use it with only one reason to change. OC (Open/Close) is when the software can be easily changed if you should increase new code instead of updating the existing code. LS (Liskov Substitution) is to create software with interchangeable codes, this is, should existing a contract that permits it be substituted by other codes (reusable code). IS (Interface Segregation) is the orientation for professionals to avoid things that they do not use. And last, DI (Dependency Inversion) is the code that implements the highest level of code which does not depend on code to implement details of level more less.

In another look, the book Dive Into Design Patterns by Alexander Shvets, approaches the principle talking way simplified: (SR) A class should have only one reason for change. (OC): The classes should have open to extension but closed for modify, (LS): when extend a class, remember that you should be able to spend objects of subclass in place of super class without break the code. (IS): Clients not should be forced to dependence of methods that not use. (DI): the highest level classes not dependence of classes the least level. Both should depend on abstractions, the abstraction shouldn’t depend on details. Details should depende of abstractions.

image

Fig. 1: Simple Diagram to illustrate S.O.L.I.D. principles

About Fig.1 to view simplify form and illustrate didactic way, we consider examples use case with application over all principles:

1 (SR): Your class has been created with single responsibility, this is, nothing like methods to make or take all operations relationship with other classes, for example, one attribute inside class Student called type or degree with imaginary abstraction about it and without a correct thing about it.

2 (OC): Thinking like a write-like view in the classes Person, Student and Professor because this is open to extend but closed to modify. That way, you design it with a mindset correct about them.

3 (LS): Yours classes or interfaces must be designing to possible definition of substitution through of one same types present in child corresponding the father according Babara's (Liskov Substitution) recommendation, anything like that must make to declare a specific useful attribute to type of subclass is the same type of super-class (your father). In the diagram the class Professor is a Person, it is, instance of Person like Person person = new Professor() (simplifying illustrate). Another example for this, thinking about another abstraction, is the class "Movie" that have two attributes called "play" and "increaseVolume" attends the class child "TheLionKing" but this second attribute not attend the class "ModernTimes'' because is movie mute and isn't logic to increase on her but instead just to TheLionKing.

4 (IS): Segregated is separate, isolated from anything, so, its view in the diagram is to isolate the function that is specific over the domain in this case. The attribute "Degree" of interface Course is segregated to another abstraction with an interface called Degree because it is to be used in specific cases.

5 (DI): Implementations are concrete classes made like for example new [Class Name] and abstractions are the class models to construct the mindset about never staying stuck in any class. Not depend on one class concrete when possible in constructing an abstraction class use the interface instead, without strong coupling. In addition, not give one command new in any class that references another concrete class instead invert the control like a constructor at class associate that implements one interface by abstraction for multiple options. For example: Class DramaCategory implements Category {...}, Interface Category {...} (like another abstraction and scope not mentioned in the diagram above) in the target class and make up in your construct a method that has an argument the interface in question.

To end this thinking, what is Software Architecture? is the form given to software by creators, that is, that form is a division of software in components, in organization about it and in the modes of commuting each other. The purpose is to ease up the development, deploying, operating and maintaining of software.

"In general, the newest programmers shouldn't think that is crazy or insist that all is new and the rules of the past are his. If they thinking this, are very so much wrong about it. The rules haven't changed, that way, although we have diverse languages, frameworks and paradigms, the rules are the same since Alan Turing wrote your first code of machine in 1946."

Compartilhe
Comentários (0)