API Basic Visibility ko - LIHACHTETAN/ClassicUO-BadNewbie-BasicIDE GitHub Wiki
Public / Private
ClassicUO โข Basic
Public์ ๋ชจ๋ ๋ฉค๋ฒ๋ฅผ ์ธ๋ถ ์ฝ๋์ ๊ณต๊ฐํฉ๋๋ค. Private๋ ๊ฐ์ ๋ชจ๋์ ํจ์, ํ๋ก์์ , ์ด๊ธฐํ ์์์๋ง ์ ๊ทผํ ์ ์์ต๋๋ค. ํ์ ์๋ ํธ์ถ์ด ์๋ ์ ์ธ ์์ ์๋๋ค.
์ ํํ ๊ตฌ๋ฌธ
Public declaration
Private declaration
๋งค๊ฐ๋ณ์
visibilityโ visibility: Public ๋๋ Private์ ๋๋ค. ์๋ตํ๋ฉด ๋ชจ๋ SUB/FUNCTION์ ๊ณต๊ฐ, VAR/DIM/CONST๋ ๋น๊ณต๊ฐ์ ๋๋ค.declarationโ declaration: SUB/FUNCTION, ์ค์นผ๋ผ VAR/DIM ๋๋ CONST์ ๋๋ค. Public์ Module๊ณผ ํ์ผ ์์ค ์ ์ธ์๋ ์ธ ์ ์์ต๋๋ค. ํ์ผ ์์ค์ด๋ ํ๋ก์์ ๋ณธ๋ฌธ์ Private๋ ๊ธ์ง๋ฉ๋๋ค. ๋ฉค๋ฒ ์ ์ธ ์ด๋ฆ์๋ ์ ์ ๋ฃ์ง ์์ต๋๋ค.
๋ฐํ๊ฐ
Public๊ณผ Private๋ ๊ฐ์ ๋ฐํํ์ง ์๊ณ ํ๋ ํ์์ด๋ ํจ์ ๊ฒฐ๊ณผ๋ ๋ฐ๊พธ์ง ์์ต๋๋ค. Normalize(12)๋ RETURN์ผ๋ก Integer 10์ ๋ฐํํฉ๋๋ค. NextCount()๋ ์ ๊ฐ์๋ฅผ ๋ฐํํ๋ฉฐ TRUE/FALSE๊ฐ ์๋๋๋ค.
๋์
- Module ์์์๋ ์์ ์ ์งง์ ์ด๋ฆ๊ณผ ์ ์ฒด ์ด๋ฆ์ ์ธ ์ ์์ต๋๋ค. ์ธ๋ถ์์๋ ModuleName.Member๋ก Public๋ง ์ ๊ทผํฉ๋๋ค. Public์ด ์งง์ ์ ์ญ ์ด๋ฆ์ ๋ง๋๋ ๊ฒ์ ์๋๋๋ค.
- Option Explicit Off์์๋ ์คํ ์ ์ ์ ๊ทผ์ ๊ฒ์ฌํฉ๋๋ค. ๋ค๋ฅธ ๋ชจ๋์ Private ์ ๊ทผ์ SC019, ์๋ชป๋ ๋ชจ๋/ํ์ ์ ์ ์ธ์ SC018 ๋๋ ๊ตฌ๋ฌธ ์ค๋ฅ์ ๋๋ค. ์ด๋ฐ ์ค๋ฅ๊ฐ ์์ผ๋ฉด ์ด๊ธฐํ ์๋ ์คํํ์ง ์์ต๋๋ค.
- ๊ณต๊ฐ ํจ์๋ ๋น๊ณต๊ฐ ๋์ฐ๋ฏธ๋ฅผ ํธ์ถํ ์ ์์ผ๋ฉฐ ํธ์ถ ํจ์๊ฐ ์ ์ธ๋ ๋ชจ๋์ ๊ธฐ์ค์ผ๋ก ํ๋จํฉ๋๋ค. ๋น๊ณต๊ฐ ๋์ฐ๋ฏธ๋ IDE, ๋จ์ถํค, ์ธ๋ถ ํ๋ก์์ API์์ ๋ฐ๋ก ์์ํ ์ ์์ต๋๋ค.
- Public Const๋ ์ฌ์ ํ ๋ณ๊ฒฝ ๋ถ๊ฐ์ด๊ณ Public Var๋ ๋ณ๊ฒฝ ๊ฐ๋ฅํฉ๋๋ค. ๋ช ์์ ์ธ ์ง์ญ ๋ณ์๋ ์์ ์ ํ๋ก์์ ์์์๋ง ๋๋ช ํ๋๋ฅผ ๊ฐ๋ฆฝ๋๋ค. Private๋ ์์ค๋ฅผ ์ํธํํ๊ฑฐ๋ ์์ ์์๊ฒ ์ฝ๋๋ฅผ ์จ๊ธฐ์ง ์์ต๋๋ค.
- ๋๋ฒ๊ฑฐ์ ์งง์ ์ด๋ฆ๊ณผ Private ์ ๊ทผ์ ์ ํํ ํ๋ ์์ ๋ฐ๋ฆ ๋๋ค. ๋ชจ๋ ์์์๋ ํ๋๋ฅผ ์ฝ์ ์ ์์ง๋ง ์ธ๋ถ ํธ์ถ์๋ก ์ ํํ๋ฉด ModuleName.privateField ์์ ๊ฑฐ๋ถ๋ฉ๋๋ค.
์์
1. ๊ณต๊ฐ ์ ๊ตฌ์ ๋น๊ณต๊ฐ ๋์ฐ๋ฏธ
# value=12๊ฐ Limits.Normalize์ Clamp๋ก ์ ๋ฌ๋ฉ๋๋ค. maximum=10์ผ๋ก ์ ํํด ๋ ํจ์๋ Integer 10์ ๋ฐํํฉ๋๋ค. Main์ Normalize๋ง ํธ์ถํ๋ฉฐ ์ธ๋ถ Limits.Clamp(12) ํธ์ถ์ ๊ธ์ง๋ฉ๋๋ค.
Option Explicit On
Module Limits
Private Const maximum = 10
Private Function Clamp(ByVal value)
If value > maximum Then
Return maximum
End If
Return value
End Function
Public Function Normalize(ByVal value)
Return Clamp(value)
End Function
End Module
Sub Main()
Return Limits.Normalize(12)
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
value=12๊ฐ Limits.Normalize์ Clamp๋ก ์ ๋ฌ๋ฉ๋๋ค. maximum=10์ผ๋ก ์ ํํด ๋ ํจ์๋ Integer 10์ ๋ฐํํฉ๋๋ค. Main์ Normalize๋ง ํธ์ถํ๋ฉฐ ์ธ๋ถ Limits.Clamp(12) ํธ์ถ์ ๊ธ์ง๋ฉ๋๋ค.
2. ๋น๊ณต๊ฐ ํ๋์ ์ง์ญ ๋ณ์
# ํ์ ์ ์๋ VAR value=7์ Store ๋ด๋ถ์ ๋น๊ณต๊ฐ ํ๋์
๋๋ค. Read๋ ํ๋ 7์ ๋ฐํํ๊ณ LocalValue๋ ์์ ์ value=9๋ฅผ ์ ์ธํด ํ๋๋ฅผ ๋ฐ๊พธ์ง ์์ต๋๋ค. Main์ 7*10+9, Integer 79๋ฅผ ๋ฐํํฉ๋๋ค.
Option Explicit On
Module Store
Var value = 7
Public Function Read()
Return value
End Function
Public Function LocalValue()
Var value = 9
Return value
End Function
End Module
Sub Main()
Return Store.Read() * 10 + Store.LocalValue()
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
ํ์ ์ ์๋ VAR value=7์ Store ๋ด๋ถ์ ๋น๊ณต๊ฐ ํ๋์ ๋๋ค. Read๋ ํ๋ 7์ ๋ฐํํ๊ณ LocalValue๋ ์์ ์ value=9๋ฅผ ์ ์ธํด ํ๋๋ฅผ ๋ฐ๊พธ์ง ์์ต๋๋ค. Main์ 7*10+9, Integer 79๋ฅผ ๋ฐํํฉ๋๋ค.
3. ๊ณต๊ฐ ์์์ ๋ด๋ถ ์นด์ดํฐ
# Public Const increment=2๋ Counter.increment๋ก ์ฝ์ต๋๋ค. Private count๋ 1๋ก ์์ํฉ๋๋ค. NextCount๋ increment๋ฅผ ๋ํด 3์ ์ ์ฅํ๊ณ ๋ฐํํฉ๋๋ค. Main์ 3*10+2, Integer 32๋ฅผ ๋ฐํํฉ๋๋ค. ์ธ๋ถ Counter.count ์ ๊ทผ๊ณผ increment ๋ณ๊ฒฝ์ ๊ธ์ง๋ฉ๋๋ค.
Option Explicit On
Module Counter
Public Const increment = 2
Private Var count = 1
Public Function NextCount()
count += increment
Return count
End Function
End Module
Sub Main()
Var result = Counter.NextCount()
Return result * 10 + Counter.increment
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
Public Const increment=2๋ Counter.increment๋ก ์ฝ์ต๋๋ค. Private count๋ 1๋ก ์์ํฉ๋๋ค. NextCount๋ increment๋ฅผ ๋ํด 3์ ์ ์ฅํ๊ณ ๋ฐํํฉ๋๋ค. Main์ 3*10+2, Integer 32๋ฅผ ๋ฐํํฉ๋๋ค. ์ธ๋ถ Counter.count ์ ๊ทผ๊ณผ increment ๋ณ๊ฒฝ์ ๊ธ์ง๋ฉ๋๋ค.