Skip to content

GOMServices/oodk-js-oop-for-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OODK-JS — Oriented-Object Development Kit for JavaScript

Concept

OODK-JS, Oriented-Object Development Kit for JavaScript is a all-in-one JavaScript library, that enriched JavaScript with all of the OOP concepts: encapsulation, inheritance, overriding, polymorphism, interface, abstraction, namespace.

Additional API are also available working around OOP concepts: conversion, cloning, serialization, iteration, comparison, sorting, debugger, reflection, event, typing, threading, RMI...

The purpose of OODK-JS is to bring to JavaScript additional pseudo-keywords to create classes, interfaces and namespaces without to install a separate compiler or learn a new language.

OODK-JS in a glance

Here is a simple class declaration written with OODK-JS compare to the exact same implementation in PHP.

<!DOCTYPE html>
<html>
<head>

  <script src="../src/oodk.js"></script>

  <script>
  OODK.config({
    'path': {
      'oodk': '../src',
      'workspace': 'workspace'
    }
  });

  OODK(function($, _){

    $.interface(function Itf1(){
      $.abstract('getAll');
    });

    $.abstract().implements(_.Itf1).class(function ClassB($, µ, _){

      $.private('a');

      $.public(function __initialize(a){

        _.a = a;

        _.self.count();
      });

      $.final().protected(function getA(){
        return _.a;
      });

      $.static(function($, µ, _){
        
        $.private('counter', 0);

        $.private(function count(){
          _.counter++;
        });

        $.public(function getCounter(){
          return _.counter;
        });
      });
    });

    $.public().extends(_.ClassB).class(function ClassA($, µ, _){

      $.private('a');

      $.protected('b');

      $.public('c');
      
      $.public(function __initialize(a, aa, b, c){

        _.a = a;
        
        µ.b = b;
        
        this.c = c;

        $.super.__initialize(aa);
      });

      $.public(function getAll(){

        var msg = [];

        msg.push('value of private a is ' + _.a + ', ');

        msg.push('value of private a (ClassB) is ' + µ.getA() + ', ');

        msg.push('value of protected b is ' + µ.b + ', ');

        msg.push('value of public c is ' + this.c );
      
        return msg.join("");
      });

      $.static(function($, µ, _){
        
        $.final().public('SUCCESS', 1);
      });
    });

    $.import("{oodk}/api/Debugger");

    var a = $.new(this.ClassA, 1, 10, "test", false);

    $.dump(a);

    $.log(a.getAll());

    $.log("value of static private counter is " + OODK.default.ClassA.self.getCounter());

    $.log("value of constant SUCCESS is " + OODK.default.ClassA.self.SUCCESS);
  });

   </script>
</head>
<body></body>
</html>

the same implementation in PHP

<?php
namespace myProject; 

interface Itf1{
function getAll();
}

abstract class ClassB implements Itf1{

private $a;

private static $counter = 0;

function __construct($a){
  $this->a = $a;

  self::count();
}

protected final function getA(){
  return $this->a;
}

private static function count(){
  self::$counter++;
}

public static function getCounter(){
  return self::$counter;
}
}

class ClassA extends ClassB{

CONST SUCCESS = 1;

private $a;

protected $b;

public $c;

function __construct($a, $aa, $b, $c){
  $this->a = $a;
  $this->b = $b;
  $this->c = $c;

  parent::__construct($aa);
}

public function getAll(){
  return 'value of private a is ' . $this->a . ', value of private a (ClassB) is ' . $this->getA() . ', value of protected b is ' . $this->b . ', value of public c is ' . $this->c;
}

}

$a = new ClassA(1, 10, "test", false);

var_dump($a);

echo "<br/>" . $a->getAll();

echo "<br/>value of static private counter is " . ClassA::getCounter();

echo "<br/>value of constant SUCCESS is " . ClassA::SUCCESS;
?>

Environments in which to use OODK

OODK is supported on browser side only (in the context of a web page page or a webworker).

NodeJS integration is on the roadmap of the next release.

Doc

A full documentation is available under the doc directory.

Test

A complete test suite is at disposal under the test directory.

However all use cases are surely not been tested, the best things to contribute is to use it on your own project and give your feedback.

Integration

Integration is really easy as OODK-JS is a all-in-one library.

<script src="path/to/source/folder/oodk.js"></script>

About

Object-Oriented Development Kit for JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages