본문 바로가기

분류 전체보기

(37)
SOLID - OOP design principle[4] - ISP In the field of software engineering, the interface segregation principle (ISP) states that no code should be forced to depend on methods it does not use. ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them 위키피디아에서는 위와 같이 설명하고 있다. 간단하게 말하면 Interface를 너무 큰 범위로 잡아서 구현부에서 사용하지 않는 메서드를 만들지..
[Android] Smart Recomposition[1] - Key[Positional memoization] 오늘 이야기하고 싶은 것은 Jetpack compose의 최적화에 대한 이야기이다. 그전에 Composable 함수의 Data -> UI 과정을 대략적으로 살펴보자. Composition Step에서는 UI Tree를 그린다. 출처: https://developer.android.com/jetpack/compose/phases Layout Step에서는 트리를 순회하며 자식 노드의 크기를 측정하고 위치를 배정하며 그것을 토대로 자신의 크기를 측정하는 일을 수행한다. 출처: https://developer.android.com/jetpack/compose/phases Drawing Step에서는 UI Tree를 선회하며 각 node를 픽셀을 그린다. 출처: https://developer.android.c..
SOLID - OOP design principle[3] - LSP an object [such as a class] may be replaced by a sub-object [such as a class that extends the first class] without breaking the program. Liskov substitution principle - Wikipedia From Wikipedia, the free encyclopedia Object-oriented programming principle "Substitutability" redirects here. For the economic principle, see Substitute good. Liskov substitution was introduced by Barbara Liskov, photo..
SOLID - OOP design principle[2] - OCP In object-oriented programming, the open–closed principle (OCP) states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" println("한식을 만들어요.") JAPAN -> println("일식을 만들어요.") else -> throw Exception("그 셰프님은 없어요.") } } } fun main() { val chefList = listOf( Chef(Chef.KOREA), Chef(Chef.JAPAN) ) chefList.forEach { chef -> chef.cook() } } 위..
SOLID - OOP design principle[1] - SRP wikipedia(https://en.wikipedia.org/wiki/SOLID)를 chat gpt한테 번역해달라고 해보았다. 소프트웨어 공학에서 SOLID는 객체 지향 설계를 이해하기 쉽고 유연하며 유지 보수하기 쉽게 만들기 위해 고안된 다섯 가지 설계 원칙을 나타내는 메모닉 약어입니다. SOLID 아이디어는 다음과 같습니다. SRP[Single-responsibility principle, 단일 책임 원칙]: "한 클래스가 변경되는 이유는 오직 하나여야 합니다." 다시 말해, 모든 클래스는 하나의 책임만을 가져야 합니다. OCP[Open–closed principle, 개방-폐쇄 원칙]: "소프트웨어 개체는 확장을 위해 열려 있어야 하지만 수정을 위해 닫혀 있어야 합니다." LSP[Liskov su..
[Kotlin] Convert string number to primitive type 콘솔에서 입력한 숫자를 적당한 Primitive number로 변환해 보려고 한다. 리턴 범위는 Double, Float, Long, Int, Short, Byte로 제한하고 진행해 보자. 일단 정수와 실수는 쉽게 나눌 수 있을 것 같다. 입력받은 string에서 "." 이라는 힌트를 받을 수 있기 때문이다. 정수형의 경우는 다음과 같다. Long의 경우 8바이트-64비트-이므로 $[-2^{63}, 2^{63}-1]$ Int의 경우 4바이트-32비트-이므로 $[-2^{31}, 2^{31}-1]$ Short의 경우 2바이트-16비트-이므로 $[-2^{15}, 2^{15}-1]$ Byte의 경우 1바이트-8비트-이므로 $[-2^{7}, 2^{7}-1]$ 위와 같은 범위를 가지기 때문에 범위에 따라서 명확하게..
Open Graph Protocol Open Graph Protocol(OGP)은 웹 페이지가 소셜 미디어 플랫폼에서 공유될 때 웹페이지의 메타데이터를 정의하기 위해서 페이스북(메타)에서 시작한 프로토콜이다. 지금은 다른 소셜 미디어 플랫폼과 웹 검색 엔진에서도 지원하고 있다. OGP는 웹 페이지의 제목, 설명, 이미지 등과 같은 핵심 정보를 명시하기 위해 태그를 사용한다. https://ogp.me/ 에서 설명하고 있는 OGP이다. 쉽게 말해서 웹 미리보기를 제공하기 위한 프로토콜이다. 확인해 보자. OGP website html에서 meta tag를 가지고 있는 속성을 가지고 온 것이다. 타이틀, 내용, 그리고 이미지 링크와 이미지 정보를 제공함으로서 우리가 흔히 보는 미리보기를 형성할 수 있도록 내용을 제공하고 있다. 이를 통하여 위..
[Kotlin] Calculator without Overloading Primitive type의 변수 2개를 변수로 연산하는 binary operation을 만들어 보려고 한다. 코틀린 Int의 super class인 Number class를 찾아가 보면 다음과 같다. public abstract class Number { public abstract fun toDouble(): Double public abstract fun toFloat(): Float public abstract fun toLong(): Long public abstract fun toInt(): Int public abstract fun toShort(): Short public abstract fun toByte(): Byte // Char는 고려하지 않음 } 연산의 변수를 명시적으로 작성해주려..