Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Support object oriented paradigm #6

Open
2 tasks
TheAwiteb opened this issue Mar 17, 2023 · 0 comments
Open
2 tasks

Support object oriented paradigm #6

TheAwiteb opened this issue Mar 17, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@TheAwiteb
Copy link
Owner

TheAwiteb commented Mar 17, 2023

Object oriented

Object oriented programming is a programming paradigm based on the concept of "objects" and "classes", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).

Classes

A class is a template for objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). Classes support inheritance, which is the ability to create a new class from an existing class. The new class is called a derived class, and the existing class is called a base class. The derived class inherits the base class's members, and can add its own members. Classes can also be used as interfaces, which is a mechanism for specifying the behavior that a class must implement.

Objects

An object is a unique instance of a data structure that is defined by its class. An object comprises both data members (class variables and instance variables) and methods.

Examples

In this example, the class defines a single method. When called, it prints the string "Hello, world." The example also creates an instance of the class and calls its method.

@HelloWorld{<
    ~say_hello{<
        println<"Hello, world.">;
    >}
>}

~main<argc><argv>{<
    hello = HelloWorld<>;
    hello.say_hello<>; // prints "Hello, world."
>}

In this example, the class defines a constructor that takes a name as an argument and stores it in a member variable. The class also defines a method that prints a message using the name.

@Greeter{<
    // self.name value will be nil by default
    -name;

    // Function that is called when the class is instantiated
    ~originator<self><name>{<
        self.name = name;
    >}

    ~greet<self>{<
        println<format<"Hello {}"><self.name>>
    >}
>}

~main<argc><argv>{<
    greeter = Greeter<"World">;
    greeter.greet<>; // prints "Hello World"
>}

As you can see, the originator function is called when the class is instantiated. And it is optional. If you don't define it, the class will be instantiated without any arguments, and the member variables will be set to nil.

Phases

For supporting the object oriented paradigm, will be three tow phases.

First phase [v0.3.0]

For this phase, the object oriented paradigm will be implemented without the inheritance.

Second phase [v0.4.0]

For this phase, the object oriented paradigm will be implemented with inheritance.

  • Second phase to support object oriented paradigm
@TheAwiteb TheAwiteb added the enhancement New feature or request label Mar 17, 2023
@TheAwiteb TheAwiteb added this to the v0.4.0 milestone Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant