OOP
Classes and OOP
Complete OOP guide for PriyoScript with instance/static/inheritance and API usage.
Theory
Object-Oriented Programming (OOP) organizes code around objects that contain state (data) and behavior (methods). In PriyoScript, classes are declared using lisaaFamily, objects are created using priyoCreate, current instance is accessed with priyoSelf, and inheritance is handled through lisaaInherit + priyoParent. OOP is useful when you want reusable, real-world models such as students, courses, wallets, accounts, and services.
Current OOP Features (Stable)
- Class declaration with
lisaaFamily- Object creation withpriyoCreate- Constructor pattern usinginit(...)- Instance members viapriyoSelf- Inheritance withlisaaInherit- Parent constructor/method access viapriyoParent- Static methods/fields vialisaaStable- Public-by-default member access - Access modifiers (lisaaOpen,lisaaPersonal,lisaaGuarded) - Interface declaration (
lisaaAgreement) and class contract (lisaaFollow)
OOP API Table
| Category | Syntax | Description |
|---|---|---|
| Class | lisaaFamily Name { ... } | Declares a class blueprint |
| Constructor | lisaaTask init(...) { ... } | Initializes object during creation |
| Instance method | lisaaTask method(...) { ... } | Method callable on object instance |
| Instance field | priyoSelf.field = value | Stores object-specific data |
| Object creation | priyoCreate Name(...) | Creates class instance |
| Inheritance | lisaaFamily Child lisaaInherit Parent { ... } | Child class extends parent |
| Parent constructor | priyoParent(...) | Calls parent init from child |
| Static method | lisaaStable lisaaTask method(...) | Class-level method |
| Static field usage | ClassName.field | Class-level state |
| Public access | obj.field, obj.method() | Members are public by default |
| Private access | lisaaPersonal ... | Accessible only inside owner class |
| Protected access | lisaaGuarded ... | Accessible in owner + subclasses |
| Interface | lisaaAgreement Name { ... } | Declares class behavior contract |
| Implements | lisaaFamily A lisaaFollow I | Enforces interface methods |
Example 1: Basic Class + Instance Method
monalisa {
lisaaFamily Student {
lisaaTask init(name) {
priyoSelf.name = name
}
lisaaTask intro() {
priyoTell("I am " + priyoSelf.name)
}
}
priyoKeep s = priyoCreate Student("mona")
s.intro()
}Explanation:
Studentclass defines one field (name) and one instance method (intro).init(name)runs automatically duringpriyoCreate Student("mona").priyoSelf.namestores the value for this specific object.s.intro()reads object state and prints it. Output:
I am monaExample 2: Static vs Instance API
monalisa {
lisaaFamily MathUtil {
lisaaStable lisaaTask square(x) {
priyoGiveBack x * x
}
lisaaTask cube(x) {
priyoGiveBack x * x * x
}
}
priyoTell(MathUtil.square(5))
priyoKeep m = priyoCreate MathUtil()
priyoTell(m.cube(3))
}Explanation:
squareis static, so it is called on class:MathUtil.square(5).cubeis instance method, so object creation is required.- This separation helps keep utility methods static and object-specific behavior instance-based. Output:
25
27Example 3: Inheritance + Parent Constructor
monalisa {
lisaaFamily Person {
lisaaTask init(name) {
priyoSelf.name = name
}
}
lisaaFamily Teacher lisaaInherit Person {
lisaaTask init(name, subject) {
priyoParent(name)
priyoSelf.subject = subject
}
lisaaTask profile() {
priyoTell(priyoSelf.name + " teaches " + priyoSelf.subject)
}
}
priyoKeep t = priyoCreate Teacher("piue", "Math")
t.profile()
}Explanation:
TeacherextendsPerson, so it inherits parent behavior.priyoParent(name)initializes inherited part first.- Child then sets its own field
subject. - Final method combines parent + child data. Output:
piue teaches MathExample 4: Public Member Access
monalisa {
lisaaFamily Course {
lisaaTask init(title, credits) {
priyoSelf.title = title
priyoSelf.credits = credits
}
}
priyoKeep c = priyoCreate Course("Compiler Design", 4)
priyoTell(c.title)
priyoTell(c.credits)
}Explanation:
- PriyoScript class members are public by default in current stable model.
c.titleandc.creditscan be directly read outside class methods. Output:
Compiler Design
4Example 5: Static Field Pattern
monalisa {
lisaaFamily Counter {
lisaaStable count = 0
lisaaTask init() {
Counter.count = Counter.count + 1
}
lisaaStable lisaaTask total() {
priyoGiveBack Counter.count
}
}
priyoCreate Counter()
priyoCreate Counter()
priyoTell(Counter.total())
}Explanation:
countis class-level shared state, not per-object state.- Each new object increments same static field.
Counter.total()returns global count. Output:
2Example 6: Interface + Access Modifiers
monalisa {
lisaaAgreement Greeter {
lisaaTask greet(name)
}
lisaaFamily Human lisaaFollow Greeter {
lisaaPersonal priyoKeep code = "H-1"
lisaaOpen lisaaTask greet(name) {
priyoGiveBack "Hi " + name
}
lisaaOpen lisaaTask revealInside() {
priyoGiveBack priyoSelf.code
}
}
priyoKeep h = priyoCreate Human()
priyoTell(h.greet("mona"))
priyoTell(h.revealInside())
}Explanation:
lisaaAgreementdefines required methods for implementers.Human lisaaFollow Greetermust implementgreet(name)with matching parameter count.codeislisaaPersonal, so it can only be accessed insideHumanmethods.
Output:
Hi mona
H-1Practice Questions
Concept Check
- When should a method be
staticinstead of instance-level? 2. Why mustpriyoParent(...)be called first in childinit? 3. What is the practical difference betweenpriyoSelf.nameandClassName.count?
Related Docs
Last updated on