Skip to content

๐Ÿฆ’์•ˆ๋“œ๋กœ์ด๋“œ ์ปจ๋ฒค์…˜๐Ÿฆ’

JinHo Jeong edited this page Sep 11, 2023 · 4 revisions

Package Path

๊ฒฝ๋กœ๋Š” ๊ผญ ์†Œ๋ฌธ์ž๋กœ ์ž‘์„ฑ๋˜์–ด์•ผ ํ•œ๋‹ค.

์–ธ๋” ๋ฐ”๊ฐ€ ํฌํ•จ๋˜์–ด์„œ๋Š” ์•ˆ๋˜๋ฉฐ, ํ•„์š”ํ•œ ๊ฒฝ์šฐ camelCase๋กœ ์ž‘์„ฑํ•œ๋‹ค.

// Do 
com.wapp.app.food

// Don't com.wapp.app.food_ingredient

// Do com.wapp.app.foodIngredient

ํ”„๋กœํผํ‹ฐ

๋ทฐ๋ชจ๋ธ, ์–ด๋Œ‘ํ„ฐ์˜ ํ”„๋กœํผํ‹ฐ ๋ช…์€ ํ’€๋„ค์ž„์„ ์‚ฌ์šฉ

val addTaskViewModel: AddTaskViewModel by viewModels()
val addTaskAdapter = AddTaskAdapter()

ํด๋ž˜์Šค ๋‚ด๋ถ€ ๋‹จ๋ฝ ๋ฐฐ์น˜ ์ˆœ์„œ

  1. ํ”„๋กœํผํ‹ฐ
  2. ์ƒ์„ฑ์ž
  3. init
  4. onCreate
  5. onCreateView
  6. Function
    • ์ถ”์ƒํ™” ๋ ˆ๋ฒจ์— ๋งž๊ฒŒ ๋†’์€ ์ˆœ์„œ๋Œ€๋กœ ๋ฐฐ์น˜ํ•œ๋‹ค.
  7. onDestroy
  8. companion object

์กฐ๊ฑด๋ฌธ

else if ์‚ฌ์šฉ ๊ธˆ์ง€ -> when์œผ๋กœ ๋ณ€ํ™˜ else๋„ ์ง€์–‘ ๊ณ ๋ ค

if (true) {
    foo()
} else {
    bar()
}

// else ์ง€์–‘ bar() if (true) { foo() }

-> ์ฐธ์ด ์•„๋‹Œ ๊ฒƒ์„ ๋จผ์ € return์œผ๋กœ ๋นผ๋ฒ„๋ฆผ.

if (false){ //toDoElse return }

when

  • ํ•œ ์ค„์— ๋“ค์–ด๊ฐ€๋Š” when ๋ถ„๊ธฐ๋Š” ์ค‘๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.
when (value) {
    0 -> return
    // ...
}
  • ์—ฌ๋Ÿฌ๊ฐœ์˜ ์กฐ๊ฑด์„ ๋™์‹œ์— ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐย >๋ฅผ ํฌํ•จํ•œ ๋ธ”๋ก์€ ๋‚ด๋ ค์„œ ์ž‘์„ฑํ•œ๋‹ค.
when (value) {
    foo -> // ...
    bar,
    baz
    -> return
}

ํ•จ์ˆ˜๋ช… prefix

๋น„๋™๊ธฐ ํ•จ์ˆ˜

  • fetch: Read
  • post : Write view(viewModel.fetchData) -> viewModel(repo.fetchData) -> repo(source.fetchData)

์ถ”๊ฐ€

  • add: list ์•ˆ์— ๋„ฃ์„ ๋•Œ
  • create: ์ƒˆ๋กœ ์ƒ์„ฑ

์กฐํšŒ

  • get: any
  • find: nullable any
  • is, has: boolean

ํ™”๋ฉด์ „ํ™˜

  • show[Dialog]
  • start[Activity]
  • navigate[Fragment]

ํ™”๋ฉด ๊ฐฑ์‹ 

  • show
  • invalidate

์ƒ์ˆ˜

๋Œ€๋ฌธ์ž + SnakeCase๋กœ ์ž‘์„ฑํ•œ๋‹ค.

์ฐธ๊ณ  ๋ ˆํผ๋Ÿฐ์Šค

https://kotlinlang.org/docs/coding-conventions.html

https://developer.android.com/kotlin/style-guide?hl=ko

Architecture


Model class naming Rule

Data Layer์—์„œ ํ†ต์‹ ์„ ์œ„ํ•œ ๋ชจ๋ธ์ธ ๊ฒฝ์šฐ, [๋ช…์‚ฌ] + Response๋กœ ์ž‘์„ฑํ•œ๋‹ค.

class UserResponse { }

Data Layer์—์„œ ๋‚ด๋ถ€ DB๋ฅผ ์œ„ํ•œ ๋ชจ๋ธ์ธ ๊ฒฝ์šฐ, [๋ช…์‚ฌ] + Entity๋กœ ์ž‘์„ฑํ•œ๋‹ค.

class UserEntity { }

Domain Layer์—์„œ ๋„๋ฉ”์ธ ๋ชจ๋ธ์ธ ๊ฒฝ์šฐ, [๋ช…์‚ฌ]๋กœ ์ž‘์„ฑํ•œ๋‹ค.

class User { }

Presentation Layer์—์„œ Ui๋ฅผ ์œ„ํ•œ ๋ชจ๋ธ์ธ ๊ฒฝ์šฐ, [๋ช…์‚ฌ] + Model๋กœ ์ž‘์„ฑํ•œ๋‹ค.

class UserModel { }

Mapper Rule

์ถœ๋ฐœ์ง€ Model์—์„œ Extension์„ ํ†ตํ•ด ๊ตฌํ˜„ํ•œ๋‹ค.

์ด๋ฆ„์€ to + [๋„์ฐฉ์ง€ ๊ณ„์ธต]์œผ๋กœ ๊ตฌ์„ฑํ•œ๋‹ค.

class UserResponse {
   fun toDomain(): User = User(...)
}

UseCase Rule

UseCase๋Š” [๋ช…์‚ฌ] + UseCase๋กœ ์ž‘์„ฑํ•œ๋‹ค.

UseCase ํด๋ž˜์Šค๋Š” ๋‹จ ํ•˜๋‚˜์˜ invoke UseCase ํ•จ์ˆ˜๋ฅผ ๊ฐ€์ง„๋‹ค.

UseCase๋Š” Functional Naming Rule์„ ์‚ฌ์šฉํ•˜๋˜, ํ•จ์ˆ˜์™€์˜ ํ˜ผ๋™์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ทœ์น™์„ ๋”ฐ๋ฅธ๋‹ค.

  • ๋ณต์ˆ˜ํ˜•์ธ ๊ฒฝ์šฐ, s โ†’ List๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

Xml / Resource


๋ทฐ ID ๋„ค์ด๋ฐ

  • ๊ธฐ๋ณธ ํ˜•์‹:ย [what]\\_[where]\\_[des]ย ex) tv_addCalendar_titleHeader
    • ์„น์…˜์„ ํ™•์‹คํ•˜๊ฒŒ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • ์–ธ๋”๋ฐ”๋กœ ๊ตฌ๋ถ„๋˜์–ด ์›ํ•˜๋Š” ์ •๋ณด๋ฅผ ๊ณจ๋ผ ์ฝ๊ธฐ ํŽธํ•˜๋‹ค.
    • des๋ฅผ ์ฝ์„ ๋•Œ์—๋Š” ๊ตฌ๋ถ„ํ•ด์„œ ์ฝ์„ ์ผ์ด ์—†๋‹ค.
  • ๊ฐ ์ ˆ์—์„œ ๋‘ ๋‹จ์–ด ์ด์ƒ์ด ํ˜ผ์šฉ๋  ๋•Œ๋Š” camel case๋กœ ์ž‘์„ฑ.
  • ์นด๋ฉœ ์ผ€์ด์Šค๋กœ ๊ตฌ๋ถ„๋˜์ง€ ์•Š๋Š” ๋ทฐ(switch, toolbar, ...)๋Š” ํ’€ ๋„ค์ž„์„ ์‚ฌ์šฉ.
  • ์ ‘๋‘์‚ฌ๋Š” simple style(textView -> tv)
tv TextView
iv ImageView
cb CheckBox
rv RecyclerView
et EditText
nsv NestedScrollView
switch Switch
btn Button

๋ ˆ์ด์•„์›ƒ prefix

  • item_<what>: ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ ๋ทฐ ์•„์ดํ…œ ๋ ˆ์ด์•„์›ƒ์— ์‚ฌ์šฉ
  • view_<what>: ์ปค์Šคํ…€ ๋ทฐ ๋ ˆ์ด์•„์›ƒ์— ์‚ฌ์šฉ

๋ฆฌ์†Œ์Šค ๋„ค์ด๋ฐ

Color

<!--color ๋ฆฌ์†Œ์Šค ์ •๋ฆฌ-->
<color name="light_gray">#E4E4E4</color>
<color name="gray">#8D8D8D</color>
<color name="gray_alpha_30">#30000000</color>

<!--์ƒ‰ ๋ณ€์ˆ˜ wHeRe_wHAt. ์—ฌ๋Ÿฌ ๊ณณ์—์„œ ์‚ฌ์šฉ๋œ๋‹ค๋ฉด where ์ƒ๋žต ๊ฐ€๋Šฅ.--> <color name="saveSchedule_titleText">@color/light_gray</color> <color name="yearCalendarView_titleText">@color/gray</color> <color name="close_background">@color/gray_alpha_30</color>

description์€ ํ…Œ๋งˆ ์†์„ฑ์œผ๋กœ ๋ถ„๋ฆฌ. ex)ย <item name="titleTextColor">@color/yellow_500</item>

Test


ํ•จ์ˆ˜ ๋„ค์ด๋ฐ : ๋ฐฑํ‹ฑ๊ณผ ๊ณต๋ฐฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ์„ฑํ•˜๊ธฐ

๊ธฐํƒ€


Utils

utils ํŒจํ‚ค์ง€๋Š” ์ตœ๋Œ€ํ•œ ์ง€์–‘ํ•˜๋ฉฐ, ๊ณตํ†ต์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ณณ์ด ๊ฐ™์€ ๋ ˆ์ด์–ด, ๋‹ค๋ฅธ ํด๋ž˜์Šค ์„ธ ๊ฐœ ์ด์ƒ์ผ๋•Œ, ํ•ด๋‹น ๋ ˆ์ด์–ด์—์„œ ๊ตฌ์„ฑํ•œ๋‹ค.

Line

  • 1์ค„์— 100์ž๋ฅผ ๋„˜์ง€ ์•Š๋„๋ก ์ž‘์„ฑํ•œ๋‹ค.
  • ์ฝ”๋“œ๊ฐ„์˜ ๊ฐ„๊ฒฉ์€ 2์ค„์ด์ƒ ๊ฐ„๊ฒฉ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋„๋ก ํ•œ๋‹ค.(์ตœ๋Œ€ 1์ค„ ์ค„๋ฐ”๊ฟˆ)
  • ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐœ์ˆ˜์™€ ์ƒ๊ด€์—†์ด 100์ž ์ด์ƒ์ด๋ฉด ๊ฐœํ–‰ํ•œ๋‹ค.

Parameter

  • ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ 2๊ฐœ ์ด์ƒ์ด๋ฉด ์ด๋ฆ„์„ ๋ช…์‹œํ•œ๋‹ค.
  • ์ค„๋ฐ”๊ฟˆ์ด ํ•„์š”ํ•˜๋ฉด ๋ชจ๋“  ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ค„๋ฐ”๊ฟˆํ•œ๋‹ค.

Method chain

  • Builder๋“ฑ ์—ฌ๋Ÿฌ ํ•จ์ˆ˜๋ฅผ chaining์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์ค„๋ฐ”๊ฟˆ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ,ย .์ „์— ์ค„๋ฐ”๊ฟˆํ•œ๋‹ค.
ImageLoader.load(user.getProfileUrl())
        .placeholder(R.drawable.img_user_placeholder)
        .fitCenter()
        .into(binding.ivUser)

์ฐธ๊ณ  ๋ ˆํผ๋Ÿฐ์Šค

  • https://techblog.woowahan.com/2706/
  • https://developer.android.com/kotlin/style-guide?hl=ko
  • https://jeroenmols.com/blog/2016/03/07/resourcenaming/
  • https://github.com/PRNDcompany/android-style-guide
  • https://github.com/woowacourse-teams/2023-festa-go/wiki/