Skip to content

Instantly share code, notes, and snippets.

@rolroralra
Last active November 15, 2021 06:22
Show Gist options
  • Save rolroralra/ce27198c5469c65b0fa35764fd79624e to your computer and use it in GitHub Desktop.
Save rolroralra/ce27198c5469c65b0fa35764fd79624e to your computer and use it in GitHub Desktop.
Code Tip

소프트웨어 개발 3대 원칙: KISS, YAGNI, DRY

  1. KISS

    Keep It Simple Stupid!

  2. YAGNI

    You Ain't Gonna Need It!

  3. DRY

    Don't Repeat Yourself!


Refactoring

[참고 서적] https://book.naver.com/bookdb/book_detail.nhn?bid=16311029

Details

Composiong Method

  • Extract Method
  • Inline Method
  • Extract Variable (Introduce Variable)
  • Inline Temp
  • Replace Temp with Query (= Extract Method + Inline Temp)
  • Split Temporary Variable
  • Remove Assignments to Parameters
  • Replace Method with Method Object
  • Substitute Algorithm

Moving Features between Objects

  • Move Method
  • Move Field
  • Extract Class
  • Inline Class
  • Hide Delegate
  • Remove Middle Man
  • Introduce Foreign Method
  • Introduce Local Extension

Simplifying Conditional Expressions

  • Consolidate Conditional Expression
  • Consolidate Duplicate Conditional Fragments
  • Decompose Conditional
  • Replace Conditional with Polymorphism
  • Remove Control Flag
  • Replace Nested Conditional with Guard Clauses
  • Introduce Null Object
  • Introduce Assertion

Simpifying Method Calls

  • Add Parameter
  • Remove Parameter
  • Rename Method
  • Seperate Query from Modifier
  • Parameterized Method
  • Introduce Parameter Object
  • Preserve Whole Object
  • Remove Setting Method
  • Replace Parameter with Explicit Methods
  • Replace Parameter with Method Call
  • Hide Method
  • Replace Constructor with Factory Method
  • Replace Error Code with Exception
  • Replace Exception with Test

Dealing with Generalization

  • Pull Up Field
  • Pull Up Method
  • Pull Up Constructor Body
  • Push Down Field
  • Push Down Method
  • Extract SubClass
  • Extract SuperClass
  • Extract Interface
  • Collapse Hierarchy
  • Form Template Method
  • Replace Inheritance with Delegation
  • Replace Delegation with Inheritance


ConcurrentModificationException

https://jy2694.tistory.com/16

Details

// ConcurrentModificationException Case
ArrayList<String> list = new ArrayList<String>();
for(String name : list){
    list.remove(name);
}

// Solution 1
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> Remove = new ArrayList<String>();
for (String name : list) 
    Remove.add(name);
for (String name : Remove) 
    list.remove(name);

// Solution 2
ArrayList<String> list = new ArrayList<String>();
 
Iterator<String> iter = list.iterator();
while (iter.hasNext()) {
    String s = iter.next();
    iter.remove();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment