객체지향 프로그래밍 (객체지향 생활체조원칙)

[Refactoring] 객체지향 생활 체조 원칙

한 메서드에 오직 한 단계의 들여 쓰기만 한다

class Person {
		func eat() -> [Int] {
				var something = [Int]()
				
				for i in 0...10 {
						for j in 0...10 {
								something.append(i + j)
						} 
				}

				return something
		}
}
class Person {
		func eat() -> [Int] {
				var something = [Int]()
				
				for i in 0...10 {
						a(somthing, i)
				}

				return something
		}

		func a(_ somthing: [Int], _ i: Int) {
			for j in 0...10 {
						something.append(i + j)
				} 
		}
}

else문을 쓰지 않는다

func login(userName: String, password: String) {
		if userRepository.checkValid(userName, password) {
				print("Go homepage")
		} else {
				print("Failure Login)
		}
}
func login(userName: String, password: String) {
		if userRepository.checkValid(userName, password) else {
				print("Go homepage")	
				return
		} 

		print("Failure Login \\(LoginError.invalidInfo)")		
}

모든 원시 값과 문자열을 포장한다