728x90

๊ฐœ๋ฐœ 32

[Android] Live Data

์ž‘์„ฑ์ผ: 2017.07.09 LiveData ๋Š” ๊ฐ’์„ ์œ ์ง€ํ•˜๊ณ , ์ด ๊ฐ’์ด observed ์ƒํƒœ๋ฅผ ๊ฐ–๊ฒŒ ํ•ด์ฃผ๋Š” data holder ํด๋ž˜์Šค์ด๋‹ค. ์ผ๋ฐ˜์ ์ธ Observerble๊ณผ ๋‹ฌ๋ฆฌ LiveData๋Š” ์•ฑ ์ปดํฌ๋„ŒํŠธ์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด์„ ๋”ฐ๋ฅธ๋‹ค. LiveData๋ฅผ ์•ˆ๋“œ๋กœ์ด๋“œ ํ”„๋กœ์ ํŠธ์— importํ•˜๋Š” ๋ฐฉ๋ฒ•์€ adding components to your project LiveData๋Š” Observer์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด์ด STARTED ๋˜๋Š” RESUMED ์ƒํƒœ์ผ ๋•Œ๋งŒ Observer๋ฅผ ํ™œ์„ฑํ™” ์ƒํƒœ๋กœ ์—ฌ๊ธด๋‹ค. Location Sample public class LocationLiveData extends LiveData { private LocationManager locationManager; private Simp..

[Design Pattern] Observer Pattern

์ž‘์„ฑ์ผ: 2017.04.26 Observer Pattern ํ•œ ๊ฐ์ฒด์˜ ์ƒํƒœ๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์„ ๋•Œ ๋‹ค๋ฅธ ๊ฐ์ฒด๋“ค์ด ์•Œ์•„์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•œ๋‹ค. ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๋Š” ๊ฐ์ฒด(Subject) / ์ƒํƒœ์˜ ๋ณ€๊ฒฝ์„ ๊ด€์ฐฐํ•˜๋Š” ๊ฐ์ฒด(Observer Object) โžž 1:N ๊ด€๊ณ„ ์žฅ์  Loose coupling subject์™€ observer๋Š” ์„œ๋กœ์˜ ์กด์žฌ๋ฅผ ์•Œ ํ•„์š”๊ฐ€ ์—†๋‹ค. Scalability(ํ™•์žฅ์„ฑ) client-server ๊ตฌ์กฐ๋ณด๋‹ค ๋” ์ข‹์€ ํ™•์žฅ์„ฑ์„ ๊ฐ–๋Š”๋‹ค. Java Observable / Observer Observable private boolean changed = false; private Vector obs; //Observable์€ ํ•˜๋‚˜ ์ด์ƒ์˜ Observer๋ฅผ ๊ฐ–๋Š”๋‹ค. ์ธ์Šคํ„ด์Šค๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด Observer์—๊ฒŒ ์•Œ๋ ค์ค€๋‹ค..