Coder Social home page Coder Social logo

dreams's People

Contributors

matheusmessora avatar

Watchers

 avatar  avatar

dreams's Issues

OOP Manifest

Based on The ThoughtWorks Anthology: Essays on Software

1- One level of Identation per method

public void method() {
   int a = 0;
   if(a > 0) {
      if(a > 10) { 
         a++; // This is WRONG
      }
   }
}

2- Do not use the 'else' keyword.
When a given method provides one behavior for the if branch, and another behavior for the else branch, then it means that this particular method is not cohesive. It has got more than one responsibility, dealing with different behaviors.

public boolean method() {
   int years = 35;
   if(years > 21) {
     return true;
   } else { // This is WRONG
     return false; 
   }
}

3- Wrap primitive types and strings
Basically, if a variable of a primitive type has behavior, consider creating a class for it.

public class Bank {
   int balance; // Wrong
   Balance balance; // Correct
}

4- Use only one dot per line
Based on the Law of Demeter. "Only talk to your friends"

public class Bank {
    Balance balance;

   public Balance getBalance(){ return balance; }

   public void method() {
      this.getBalance().isPositive(); // WRONG
      this.isBalancePositive(); // Correct
   }

   ...
}

5- Do not abbreviate

6- Keep your classes small
A class should have 50 statements. This excludes blank lines, comments and structure closing lines.
The code should be visible inside the text editor of your IDE.

7- Do not use classes with several instance variables
A class should have only 2 instance variables.

8- Do not use static methods
Can you simple mock a static method without frameworks?
https://dzone.com/articles/why-static-bad-and-how-avoid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.