Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
11 of 24 tasks
Almas-Ali opened this issue Apr 9, 2024 · 2 comments
Open
11 of 24 tasks

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

Almas-Ali opened this issue Apr 9, 2024 · 2 comments
Labels
enhancement New feature or request OOP Object Oriented Programming proposal Radon Enhancement Proposal (REP) syntax Language Syntax
Milestone

Comments

@Almas-Ali
Copy link
Member

Almas-Ali commented Apr 9, 2024

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

  • class keyword support.
  • BuiltInClass functionality to add built in classes like we have BuiltInFunctions. We have mentioned this on Need BuiltInClass or Object for defining internal classes. #23
  • BuiltInInstance to handle classes objective behaviours.
  • Operators overloading systems to handle classes operational behaviours.

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.

  • Abstraction support.
  • abstract keyword support.
abstract class AbstractClass() {
    fun some_method1(args1, args2, ...) # No implementations
    fun some_method2(args1, args2, ...) # No implementations
}

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.
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
    }
}
  • Polymorphism support.
    Operator overloading is a part of polymorphism, which is already done.
    If anything missing, will be updated later.
  • Inheritance support.
  • Single Inheritance.
  • Multiple Inheritance.
  • Multilevel Inheritance.
  • Hierarchical Inheritance.
  • Hybrid Inheritance.
class ParentClass {
    fun __constructor__(something) {
        this.something = something
    }

    fun some_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.

@Almas-Ali Almas-Ali pinned this issue Apr 9, 2024
@Almas-Ali Almas-Ali added enhancement New feature or request syntax Language Syntax OOP Object Oriented Programming proposal Radon Enhancement Proposal (REP) labels Apr 9, 2024
@angelcaru
Copy link
Contributor

Operator overloading added in #50

@Almas-Ali Almas-Ali changed the title Object Oriented System Enhancement (REP-2) Object Oriented System Enhancement Proposal. (REP-2) Apr 10, 2024
@Almas-Ali
Copy link
Member Author

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

@Almas-Ali Almas-Ali added this to the v0.1 release milestone May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OOP Object Oriented Programming proposal Radon Enhancement Proposal (REP) syntax Language Syntax
Projects
None yet
Development

No branches or pull requests

2 participants