Upload
widhian-bramantya
View
159
Download
1
Embed Size (px)
Citation preview
MODULARIZING RESTFUL WEB SERVICE MANAGEMENT
WITHASPECT 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]
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
INTRODUCTION
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
Introduction
How RESTful Web Service Works
Browser / Other
.htaccess
REST API
Get Request
Process API
Method I ()
Database
Method I () Method I ()
request
response
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
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
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
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.
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).
PROPOSED CONSTRUCTION
Proposed Construction
1 2 3
Crosscutting Concern Identification
UML, ERD, and API Design Conversion
RESTful Web Service Development
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>
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}/
Proposed Construction
RESTful Web Service Development
OOPGet Request
AuthenticationFirst LoggingFirst CachingProcess API
Last CachingLast Logging
Method I Method II Method III
Class
Crosscutting Concern
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
Proposed Construction
RESTful Web Service Development
<?phpclass User { function processApi(){ ... }}$api = new User();$api->processApi();?>
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; }}?>
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() {..} }?>
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); }}?>
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 { ???}?>
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) { ... }}?>
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 }}?>
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 }}?>
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 }}?>
RESULT & ANALYSIS
Result and Analysis
PHP
E-comme
rce
Authentication
CachingLogging
Language Case Study
Aspects
82 APIs
APIs
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
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
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:-
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
Result and Analysis
Summary
Separation of Concerns (SoC) OOP+AOP
Size OOP
Coupling OOP
Cohesion OOP+AOP
The Best
CONCLUSION
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
Thank You