radon-project / radon

The Radon Programming Language
https://radon-project.github.io
GNU General Public License v3.0
23 stars 3 forks source link

Object Oriented System Enhancement Proposal. (REP-2) #49

Open Almas-Ali opened 7 months ago

Almas-Ali commented 7 months ago

We are making Radon a true object oriented language like Python. We are willing to add almost all natures a OOP language supports.

A basic sudo implementation of OOP in Radon will be like this.

class MyClass {
    fun __constructor__(this, any, others, args=null) {
        this.any = any
        this.others = 16*others
    }

    fun __add__(this, other) {
        return MyClass(
            this.any + other.any,
            this.others + other.others,
            this.args + other.args
        )
    }

    fun __destructor__(this) {
        pass
    }
}

Realistic OOP behaviors.

class NewClass(AbstractClass) { fun some_method1(args1, args2, ...) # Have to complete anyway {

implementations

}
fun some_method2(args1, args2, ...) # Have to complete anyway
{
    # implementations
}

}

- [ ] Encapsulation support.
- [ ] `public`, `private`, `protected` keyword support.
```radon
class ExampleClass {
    fun __constructor__(something) {
        this.something = something
    }

    # All methods by default public. explicitly definitions allowed.
    fun some_method() {
        return 123
    }
    public fun public_method() -> 0

    private fun private_method() {
        return 123
    }

    protected fun protected_method() {
        return 123
    }
}

class ChildClass(ParentClass) { fun constructor(something_new) { this.something_new = something_new super().constructor(something) } }

child = ChildClass() child.some_method() # will work!



We will update this issue as we change our plans.
angelcaru commented 7 months ago

Operator overloading added in #50

Almas-Ali commented 7 months ago

More OOP concepts has been updated as proposal. A huge list to complete!! 🥱