Design Patterns Handbook
  • Introduction
  • Creational Patterns
    • Builder
    • Factory
    • Abstract Factory
    • Factory Method
    • Prototype
    • Singleton
    • Object Pool
    • Revealing Constructor
  • Structural Patterns
    • Adapter
    • Composite
    • Proxy
    • Flyweight
    • Facade
    • Bridge
    • Decorator
    • Private Class Data
  • Behavioral Patterns
    • Template Method
    • Mediator
    • Chain Of Responsibility
    • Observer
    • Strategy
    • Command
    • State
    • Visitor
    • Memento
    • Interpreter
    • Null Object
    • Iterator
    • Middleware
  • Clean Code Patterns
    • Extract Method
    • Clarify Responsibility
    • Remove Duplications
    • Keep Refactoring
    • Always Unit Test
    • Create Data Type
    • Comment to Better Name
    • Consistent Naming
    • If-else over ternary operator
    • Composition over Inheritance
    • Too Many Returns
    • Private to Interface
  • Anti Patterns
    • Big Ball of Mud
    • Singleton
    • Mad Scientist
    • Spaghetti Code
    • It Will Never Happen
    • Error Codes
    • Commented Code
    • Abbreviations
    • Prefixes
    • Over Patternized
    • Generic Interface over Function
Powered by GitBook
On this page
  • Company or product prefixes
  • m for member s for static

Was this helpful?

  1. Anti Patterns

Prefixes

Somehow, package name is not enough to identify a class. We should think harder before we decide to prefix all classes names with, for example company name or company first letter.

Company or product prefixes

Lets say we work for company named UmpaLumpaOfScience that is developing a product named science. We should probably avoid using these kind of prefixes.

If there is a conflict in names in one class, probably something else is wrong our class design and we need to rethink how our classes exchange data and how they work together.

public class UUser {
}

public class UScienceUser extends UUser {
}

m for member s for static

Just don't do this.

public class Task {

  private static final String[] sExcludedFields = new String[]{"mCreated", "mId"};

  private Integer mId;

  private String mTemplate;

  public Integer getId() {
    return mId;
  }

  public setId(Integer id) {
    return mId = id;
  }

  public String getTemplate() {
    return mTemplate;
  }

  public getTemplate(String template) {
    mTemplate = template;
  }

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this, SHORT_PREFIX_STYLE);
  }

  @Override
  public int hashCode() {
    return HashCodeBuilder.reflectionHashCode(this, sExcludedFields);
  }

  @Override
  public boolean equals(final Object obj) {
    return EqualsBuilder.reflectionEquals(this, obj, EXCLUDE_FIELDS);
  }
}
PreviousAbbreviationsNextOver Patternized

Last updated 5 years ago

Was this helpful?