36
MODULARIZING RESTFUL WEB SERVICE MANAGEMENT WITH ASPECT ORIENTED PROGRAMMING

Modularizing RESTful Web Service Management with Aspect Oriented Programming

Embed Size (px)

Citation preview

Page 1: Modularizing RESTful Web Service Management with Aspect Oriented Programming

MODULARIZING RESTFUL WEB SERVICE MANAGEMENT

WITHASPECT ORIENTED PROGRAMMING

Page 2: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Authors

Widhian Bramantya

Dana S. Kusumo

Bayu Munajat

School of ComputingInformatics Engineering

Telkom Universitywidhian.bramantya@gmai

l.com

School of ComputingInformatics Engineering

Telkom Universitydanakusumo@telkomuniversit

y.ac.id

School of ComputingInformatics Engineering

Telkom [email protected]

Page 3: Modularizing RESTful Web Service Management with Aspect Oriented Programming

12

34

Introduction

Outline

Proposed ConstructionRESTful Web Service

How RESTful Web Service Works

Crosscutting Concern in RESTful Web Service

Aspect Oriented Programming

Reusability Metric

Crosscutting Concern Identification

UML, ERD, API Design Conversion

RESTful Web Service Development

Result and Analysis

Conclusion

Page 4: Modularizing RESTful Web Service Management with Aspect Oriented Programming

INTRODUCTION

Page 5: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Introduction

RESTful Web Service

Show all adminGET /admin

Insert new adminPOST /admin

Show detail admin 1GET /admin/1

Update admin 1PUT /admin/1

Delete admin 1DELETE /admin/1

<resource href="/admin"> <link href="{related link}" rel="{related rel}"> <resource href="/admin/1" rel="admin"> <id_admin>1</admin> <name>bob</name> </resource> <resource href="/admin/2" rel="admin"> <id_admin>2</admin> <name>alice</name> </resource></resource>

API DB

request

response

Page 6: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Introduction

How RESTful Web Service Works

Browser / Other

.htaccess

REST API

Get Request

Process API

Method I ()

Database

Method I () Method I ()

request

response

Page 7: Modularizing RESTful Web Service Management with Aspect Oriented Programming

function processApi(){ $auth = $cache = $log = NULL; $func = str_replace("/","" , $_REQUEST['request']); $parameter = str_replace("/","", $_REQUEST['attribute']); $cache = new Cache(); $log = new Log(); $auth = new Auth(); $auth->auth_start($parameter); $log->log_start($parameter); $cache->cache_start($parameter); $result = $this->$func($parameter); $cache->cache_end($result); $log->log_end($result);}

Introduction

Crosscutting Concern in RESTful Web Service

Call Main Method

Cache Concern

Log Concern

Authentication Concern

class

Page 8: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Introduction

Aspect Oriented Programming

Authentication

First Logging

First Caching

Call Main Method

Last Caching

Last Logging

API Class

API Class

API Class

Aspect Authenticati

on

Aspect Logging

Aspect Caching

class

Authentication

First Logging

First Caching

Call Main Method

Last Caching

Last Logging

class

Authentication

First Logging

First Caching

Call Main Method

Last Caching

Last Logging

class

advice

advice

advice

Page 9: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Introduction

Reusability Metrics

Reusability

Understandability

Flexibility

Separation of Concerns

Size

Coupling

Cohesion

CDO, CDC, CDLOC

VS, LOC, NOA, WOC

CBC, DIT

LCOO

Qualities Factors Internal Attributes Metrices

Page 10: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Introduction

Reusability Metrics

No Metrics Definition

1 Concern Diffusion over Components (CDC)

Counts the number of primary components whose main purpose is to contribute to the implementation of a concern

2 Concern Diffusion over Operations (CDO)

Counts the number of primary operations whose main purpose is to contribute to the implementation of a concern

3 Concern Diffusion over LOC (CDLOC)

Counts the number of transition points for each concern through the lines of codes (concern switch)

7 Vocabulary Size (VS)

Counts the number of system component, i.e. classes or aspects.

8 Lines of Code (LOC)

Counts the number of lines of codes.

Page 11: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Introduction

Reusability MetricsNo Metrics Definition

9 Number of Attributes (NOA)

Counts the internal vocabulary of each component, i.e. the number of attributes of each class or aspect

10 Weighted Operations per Component (WOC)

Measures the complexity of component in terms of its operations.

4 Coupling Between Components (CBC)

A component (class or aspect) as a tally number of other components to which it is coupled.

5 Depth of Inheritance Tree (DIT)

Counts the maximum length of a node to a root of the tree

6 Lack of Cohesion in Operations (LCOO)

Counts the lack of cohesion of a component. (inherited class or aspect).

Page 12: Modularizing RESTful Web Service Management with Aspect Oriented Programming

PROPOSED CONSTRUCTION

Page 13: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

1 2 3

Crosscutting Concern Identification

UML, ERD, and API Design Conversion

RESTful Web Service Development

Page 14: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

Crosscutting Concern Identification

Identify & Describe Non-Functional

Concerns

Specify Functional Requirements

Identify & Specify Crosscutting

Concern Compose Crosscutting

Concerns into the UML Models

Crosscutting Concern <Name>

Description <Executive description>

Priority <Priority can be Max, Med, and Min>

List of requirements <Requirements that describe the concern>

List of models <UML models influenced by the concern>

Page 15: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

UML, ERD, and API Design Conversion

UML ERD API Design

{root}/

{resource 1}/

{…}/

{resource n}/

{id resource

1}/

{sub resource

1}/

{…}/

{sub resource

n}/

{id sub resource

1}/

Page 16: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

OOPGet Request

AuthenticationFirst LoggingFirst CachingProcess API

Last CachingLast Logging

Method I Method II Method III

Class

Crosscutting Concern

Page 17: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

OOP + AOP

Get Request

Process API

Method I Method II Method III

Class

Aspect Authentication

Aspect Logging

Aspect Caching

Page 18: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?phpclass User { function processApi(){ ... }}$api = new User();$api->processApi();?>

Page 19: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development <?php

class User { function processApi() { $func = str_replace("/","",$_REQUEST['request']); $parameter = str_replace("/","", $_REQUEST['attribute']); $log = new Log($this); $log->$func($parameter); }}?>

<?phpclass Log extend AOP { function __construct($object){ AOP::__construct($object); }}?>

<?phpclass AOP { $_inner = NULL; function __construct($object){ $this->_inner = $object; }}?>

Page 20: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?php class Log extend AOP { function __construct($object){ ... $this->inject_before_call(".*", "before_advice"); $this->inject_after_call(".*", "after_advice"); } function before_advice(){. . .} function after_advice(){. . .} }?>

<?php class AOP { $_before = array(); $_after = array(); function inject_before_call(){ $this->_before[] = array("/".$pattern."/", $method_name); } function inject_after_call() {..} }?>

Page 21: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?phpclass Log extend AOP { function __construct() { ... $this->inject_before_call(".*", "before_advice"); $this->inject_after_call(".*", "after_advice"); } function before_advice(...) {...} function after_advice(...) {...}}?>

<?phpclass AOP { $_before = array(); $_after = array(); function inject_before_call() {...} function inject_after_call() { $this->_after[] = array("/".$pattern."/", $method_name); }}?>

Page 22: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?phpclass User { function processApi() { $func = str_replace("/","", $_REQUEST['request']); $parameter = str_replace("/","", $_REQUEST['attribute']); $log = new Log(); $log->$func($parameter); }}?><?phpclass Log extend AOP { ???}?>

<?phpclass AOP { ???}?>

Page 23: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?phpclass User { function processApi() { $func = str_replace("/","", $_REQUEST['request']); $parameter = str_replace("/","", $_REQUEST['attribute']); $log = new Log(); $log->$func($parameter); }}?>

<?phpclass AOP { function __call($method_name,$params) { ... }}?>

Page 24: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?phpclass User { function __call($method_name,$params) { foreach($this->_before as $lookup) { list($pattern,$before_method_name) = $lookup; if(preg_match($pattern,$method_name)) { call_user_func_array(array( $this,$before_method_name),array( $method_name,$params)); } } ... // function to call $api->$func() ... // function to call after_advice() }}?>

<?phpclass Log extend AOP{ function before_advice($method_name,$params) { // some code to save log start }}?>

Page 25: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?phpclass User { function __call($method_name,$params) { ... // function to call before_advice() $result = call_user_func_array(array($this->_inner, $method_name),array($params); ... // function to call after_advice() }}?>

<?phpclass User{ function methodName($params) { // main API code }}?>

Page 26: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Proposed Construction

RESTful Web Service Development

<?phpclass User { function __call($method_name,$params) { ... // function to call before_advice() ... // function to call $api->$func() foreach($this->_before as $lookup) { list($pattern,$before_method_name) = $lookup; if(preg_match($pattern,$method_name)) { call_user_func_array(array($this, $before_method_name),array($method_name, $params,$result)); } } }}?>

<?phpclass Log extend AOP { function after_advice($method_name,$params,$result) { // some code to save log start }}?>

Page 27: Modularizing RESTful Web Service Management with Aspect Oriented Programming

RESULT & ANALYSIS

Page 28: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Result and Analysis

PHP

E-comme

rce

Authentication

CachingLogging

Language Case Study

Aspects

82 APIs

APIs

Page 29: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Result and Analysis

Separation of Concerns (SoC)

The Best:OOP

Concern Diffusion over Components (CDC)

0

4045 47

Concern Diffusion over Component (CDC)

OOP OOP + AOP

Metric

Conc

erns

Concern Diffusion over Operations (CDO)

0

200195

64

Concern Diffusion over Operation (CDO)

OOP OOP + AOP

Metric

Conc

erns

Concern Diffusion over Operations (CDO)

0

400453

266

Concern Diffusion over LoC (CDLoC)

OOP OOP + AOP

Metric

Conc

erns

The Best:OOP +

AOP

The Best:OOP +

AOP

Page 30: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Result and Analysis

Size

Vocabulary Size0

204060 44 44

Vocabulary Size (VS)

OOP OOP + AOP

Metric

Clas

ses

Lines of Code0

10000200003000040000 36979 36531Line of Code (LoC)

OOP OOP + AOP

Metric

Line

sNumber of Attributes

0

100

200 158 163

Number of Attributes (NoA)

OOP OOP + AOP

Metric

Attri

bute

s

Weighted Operation per Component

0

400410 452

Weighted Operations per Component (WoC)

OOP OOP + AOP

Metric

Com

plex

ity

The Best:-

The Best:OOP

The Best:OOP +

AOP

The Best:OOP

Page 31: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Result and Analysis

Coupling

The Best:OOP

Coupling Between Components (CBC)

0

200198 201

Coupling Between Component (CBC)

OOP OOP + AOP

Metric

Coup

ling

Depth of Inheritance Tree (DIT)

0

4039 39

Depth of Inheritance Tree (DIT)

OOP OOP + AOP

Metric

Dep

th

The Best:-

Page 32: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Result and Analysis

Cohesion

The Best:OOP +

AOP

Lack of Cohesion in Operations (LCOO)

0

150181 155

Lack of Cohesion in Operations (LCOO)

OOP OOP + AOP

MetricLa

ck

Page 33: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Result and Analysis

Summary

Separation of Concerns (SoC) OOP+AOP

Size OOP

Coupling OOP

Cohesion OOP+AOP

The Best

Page 34: Modularizing RESTful Web Service Management with Aspect Oriented Programming

CONCLUSION

Page 35: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Conclusion

The code of API class with OOP+AOP is still easier to be understood because

of separation between the functional requirement and aspects.1

The code of API class with OOP+AOP is more flexible than OOP if there is a

significant change in codes caused by grouping concerns.2

These finding have shown an evidence that REST-OOP+AOP is indicated more reusable than REST-OOP.3

Page 36: Modularizing RESTful Web Service Management with Aspect Oriented Programming

Thank You