Software modularity and reuse Paulo Borba Informatics Center Federal University of Pernambuco

[email protected] ◈ twitter.com/pauloborba Monday, September 20, 2010

1

Components and parametrization

Monday, September 20, 2010

2

Different devices, 15 to 60 different applications…

Different clients, different products

http://www.androidauthority.com Monday, September 20, 2010

3

Reuse problems

Monday, September 20, 2010

4

Modularity problems

Monday, September 20, 2010

5

Refactoring problematic component

Test 1 Test 2

improved component

Test 1 Test 2

...

...

Monday, September 20, 2010

refactoring

Test n

Test n

6

Patterns

Monday, September 20, 2010

7

Variability patterns (avoiding code duplication in product families) Monday, September 20, 2010

8

Template method

http://www.refactoring.com/catalog/formTemplateMethod.html Monday, September 20, 2010

9

PDC, bridge variation... class AccountRecord { private AccountRepository accounts;... public void register(Account a) { if (a != null) { String n = a.getNumero(); if (!accounts.exists(n)) { accounts.insert(a); } } } Monday, September 20, 2010

10

variation is whole data structure interface AccountRepository { void insert(Account account); Account search(String number); boolean exists(String number); } class AccountArray implements AccountRepository {...} class AccountVector implements AccountRepository {...} Monday, September 20, 2010

11

Compare patterns

Monday, September 20, 2010

12

But how are variants chosen? Monday, September 20, 2010

13

Product family assets Java files, abstract

Java files, concrete

Java files, decision ... new AccountArray ... ...

Makefiles

Monday, September 20, 2010

new AccountVector ...

14

Parametrized factory... Java files, abstract

Java files, concrete

Java file, decision ... if (...) {... new AccountArray

...

} else {... new AccountVector

Makefiles

...

} ...

Monday, September 20, 2010

15

with property (or XML) file Properties p = new Properties(); p.load(new FileInputStream("repository.prop")); ... if (p.getProperty("ACCOUNT_REP") == 1) { ... } else {...} ...

Monday, September 20, 2010

16

Property files as assets Java files, abstract

Java files, concrete

Java file, decision ... if (...) {...} else {...} ...

Property files Makefiles

ACCOUNT_REP=1 ACCOUNT_REP=2

Monday, September 20, 2010

17

Properties parametrize behavior and data Properties p = new Properties(); p.load(new FileInputStream("device_screen.prop")); ... draw(p.getProperty("SCREEN_WIDTH"),50); ...

Monday, September 20, 2010

18

Compare mechanisms

Monday, September 20, 2010

19

Analyzing subtype polymorphism • Variation point: supertypes (methods) in the program text • Variation: subtypes (including methods and fields) • Binding time: execution time, based on makefile choice (compilation/build time) • Mechanism: subtype definition, variation modularization Monday, September 20, 2010

20

Analyzing file parametrization • Variation point: expressions in the program text, and commands too (with conditionals) • Variation: constants and values, commands • Binding time: execution time, based on makefile choice (build time) • Mechanism: value instantiation, decision

Monday, September 20, 2010

21

Decision mechanisms for subtype polymorphism • Makefiles (different mains or factories)

developer

• Makefiles + property_files + conditionals • Makefiles + property_files + reflection • Input + conditionals

user

• Input + reflection

Monday, September 20, 2010

22

Environment decision, with dependency injection... class AccountRecord { private AccountRepository accounts; void setRepository(AccountRepository r) { accounts = r; } ... Not a developer decision, nor } a user decision!

Monday, September 20, 2010

23

Components • Improvement over subtype polymorphism and Java packages • not by defining subtypes of abstract classes, but of interfaces • clientship + subtype polymorphism • deployment independence • service location and management • module visibility and versions

Monday, September 20, 2010

24

Containers Client

component component

XML

Java Java Java

component component

component

Monday, September 20, 2010

25

Extending Eclipse... Monday, September 20, 2010

26

and allowing extensions
Monday, September 20, 2010

27

Acessing variations ep = Platform...getExtensionPoint("ELP_EP.languageSet"); IExtension[] extensions = ep.getExtensions(); for (IExtension e : extensions) { configs = e.getConfigurationElements(); for (IConfigurationElement c : configs) { if (c.getName().equals("language")) { ...new Path(c.getAttribute("languageFile")); } } }

Monday, September 20, 2010

28

Components in Spring

http://www.developer.com/img/articles/2005/04/13/List108.gif Monday, September 20, 2010

29

When and where to use this?

Monday, September 20, 2010

30

Parametrization via parametric polymorphism public class Record { ... public void insert(ComplaintType o) { ... } } ... Record ... Monday, September 20, 2010

31

Parametric polymorphism core assets Java file, generic Makefiles

Java files, specific ... Record ... Monday, September 20, 2010

... Record ... 32

Parametrizing data + operations public class Record< ComplaintType extends CodeIdentifiable> { ... public ComplaintType search(int code){ ... } public void insert(ComplaintType o) { ... } interface CodeIdentifiable { } int getCode(); } Monday, September 20, 2010

33

Analyzing parametric polymorphism • Variation point: class parameters (types and methods) in the program text • Variation: types (including methods) • Binding time: compilation time, based on makefile choice • Mechanism: type instantiation, variation and “common” code modularization Monday, September 20, 2010

34

Black belt parametrization! Monday, September 20, 2010

35

Smells good?

functions as parameters

artigos.each{|a| map = {} a.elements.each("DADOS-BASICOS-DO-ARTIGO"){|d| atts = d.attributes map["TITULO-DO-ARTIGO"] = atts["TITULO-DO-ARTIGO"] map["ANO-DO-ARTIGO"] = atts["ANO-DO-ARTIGO"] } a.elements.each("DETALHAMENTO-DO-ARTIGO"){|d| atts = d.attributes map["TITULO-DO-MEIO"] = atts["TITULO-DO-MEIO"] map["VOLUME"] = atts["VOLUME"] map["FASCICULO"] = atts["FASCICULO"] map["PAGINA-INICIAL"] = atts["PAGINA-INICIAL"] map["PAGINA-FINAL"] = atts["PAGINA-FINAL"] } ... Monday, September 20, 2010

36

Not only for articles... ... a.elements.each("AUTORES"){|author| map["AUTORES"] = (if map["AUTORES"] then map["AUTORES"] else [] end) + [author.attributes["NOME-PARA-CITACAO"]] } }

Monday, September 20, 2010

37

XML structure as parameter artigos.each{|a| map = {} structure = { "DADOS-BASICOS-DO-ARTIGO" => ["TITULO-DO-ARTIGO", "ANO-DO-ARTIGO"], "DETALHAMENTO-DO-ARTIGO" => ["TITULO-DO-MEIO", "VOLUME", "FASCICULO", "PAGINA-INICIAL", "PAGINA-FINAL"], "AUTORES" => ["*", "NOME-PARA-CITACAO"]} }

Monday, September 20, 2010

38

Abstracting structure details structure.keys.each {|e| a.elements.each(e) {|d| atts = d.attributes if structure[e].include?("*") then (structure[e] - ["*"]).each {|att| map[e] = (if map[e] then map[e] else [] end) + [atts[att]] } else structure[e].each {|att| map[att] = atts[att] } end } } Monday, September 20, 2010

39

Improvement is more often needed than not, so abstract to see it! Monday, September 20, 2010

40

Take notes, now! Monday, September 20, 2010

41

Components and parametrization

Monday, September 20, 2010

42

Software modularity and reuse Paulo Borba Informatics Center Federal University of Pernambuco

[email protected] ◈ twitter.com/pauloborba Monday, September 20, 2010

43

Paulo Borba Informatics Center Federal University of ...

PDC, bridge variation... class AccountRecord { private AccountRepository accounts;... public void register(Account a) { if (a != null) {. String n = a.getNumero(); if (!accounts.exists(n)) { ... Account search(String number); boolean exists(String number); .... Variation point: class parameters (types and methods) in the program text.

1MB Sizes 0 Downloads 114 Views

Recommend Documents

Paulo Borba Informatics Center Federal University of ...
Software as a Service. (SaaS). • Delivers software and data as a service over the Internet. • No need to install applications. • No need to backup or share data. • Easier to improve the service ...

Paulo Borba Informatics Center Federal University of ...
Little reuse and agility, high costs. Even with. Android! ... import java.util.Vector; import com.meantime.j2me.util.Screen; import com.meantime.j2me.util.bvg.BVGAnimator;. //#if device_graphics_transform_midp2. //# import javax.microedition.lcdui.ga

Paulo Borba Informatics Center Federal University of ...
Code cloning tool, packages. 8. Wednesday, August 18, 2010 ... Minimum TKS (kinds of tokens) int x = 0; int y = 0; int z = 0; int a = 0; int b = 0; int c = 0;. 18. Wednesday, August 18, 2010 ... POP (population): Count of code fragments of the code c

Paulo Borba Informatics Center Federal University of ...
Code cloning tool, file. Page 8. Code cloning tool, packages. Page 9 ... P-match... maps different variables and function names to different tokens if (x>0). {y=1; x=2; x=w;} else. {y=1; x=2; x=z;}. Page 17. Minimum TKS (kinds of tokens) int x = 0; i

Paulo Borba Informatics Center Federal University of ...
Check previous activities. • Log into google with your CIn account. • Access and answer today's questions (…) • Discuss class material. • what haven't you understood? what don't you agree? what haven't you liked? what are you missing to per

Paulo Borba Informatics Center Federal University of ...
Software development issues. (crisis?) □ Project cancellation rate of 25%. • 31% in another study, 16% are successful. □ development time and cost go well beyond the estimative. • in 53% of the analyzed projects. □ 75% of the analyzed syste

Denver Federal Center (2).pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Denver Federal ...

Federal University of Amazonas, Manaus, BRAZIL ...
RESULTS. Two evaluation metrics were used: • RMSE: adequate to evaluate the floating point results ... host city of all teams). • The problem of prediction of goal difference was interpreted as a temporal regression task. • We searched for a se

[PDF BOOK] Fundamentals of Federal Income Taxation (University ...
We would like to show you a description here but the site won’t allow us. Online PDF Fundamentals of Federal Income Taxation (University Casebook ...

Federal University of Technology, Owerri, Imo State ... ...
on Computational Sciences, Information Assurance, Big Data, and STEM. Education .... Room rates 2012/2014. ROOM. RATES. DEPOSIT. SUPERIOR DOUBLE.

The City University of New York - The Graduate Center, CUNY
Jul 6, 2011 - Act as a First Responder to alarms and calls for service. Observe campus activities, reporting suspicious behavior and other incidents to Central ...

National Survey - Public Policy Center - University of Iowa
Additionally, the project team brought in Knowledge Networks, a nationally .... Upon receiving the responses, the UI compiled all the expert responses into a single ..... 'social media (Facebook, twitter)' (4.7%) and 'brochures, pamphlets' (5.2%).

National Survey - Public Policy Center - University of Iowa
component of the National Driver Safety Education Campaign. ... Additionally, the project team brought in Knowledge Networks, a nationally ..... Respondents were asked to report (to the best of their knowledge) which vehicle safety ... Table 10: Tech

University of Texas Health Science Center at San Antonio.pdf
University of Texas Health Science Center at San Antonio.pdf. University of Texas Health Science Center at San Antonio.pdf. Open. Extract. Open with. Sign In.

The University of Arizona Center for Environmental Physics and ...
collaborative soil science research focused on the application of geospatial, ... for an individual that can assist in project management, including data analysis.

The University of Arizona Center for Environmental Physics and ...
The University of Arizona Center for Environmental Physics and Mineralogy and Environmental. Pedology ... immediate need for an individual that can assist in project management, including data analysis ... Please feel free to contact Craig.