web application development zsolt tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... ·...

30
Component based Development Web Application Development Zsolt Tóth University of Miskolc 2017 Zsolt Tóth (University of Miskolc) Component based Development 2017 1 / 30

Upload: others

Post on 04-Nov-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Component based DevelopmentWeb Application Development

Zsolt Tóth

University of Miskolc

2017

Zsolt Tóth (University of Miskolc) Component based Development 2017 1 / 30

Page 2: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Overview

Table of Contents

1 Overview

2 Interface-based Programming

3 Tools

4 Project Structures

Zsolt Tóth (University of Miskolc) Component based Development 2017 2 / 30

Page 3: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Overview

Software SystemProvide Services

FunctionalNon-Functional

Single UnitLooks LikeCommunicates with OthersIntegrated

ComplexUsually ModularSoftware Architectures

MVCn-TierSOA

Zsolt Tóth (University of Miskolc) Component based Development 2017 3 / 30

Page 4: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Overview

Terms

sub–system A part of the entire system that provide a well–definedfunctionality.

module A development unit that has a well–defined purpose.Modules are identified by their name.

component A module used by another module.artifact A specific version of a module. A module with a version

number.

These terms are slightly different. During the course, we will stick tothese definitions. Do not mix them.

Zsolt Tóth (University of Miskolc) Component based Development 2017 4 / 30

Page 5: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Overview

Modules, ComponentsTests

UnitComponentIntegration

DependenciesBuild processDeployment

Version numbermajor.minor.build.revisionalpha, beta, releasecandidate, commercialdistributionNever use multiple versionof the same module!

Zsolt Tóth (University of Miskolc) Component based Development 2017 5 / 30

Page 6: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Overview

Component

Standalone Development UnitSpecific Functionality

AbstractnessGranularityCommunicates via Interface

Specific TechnologiesJDBC, JPA, myBatisJ2EE, SpringJackson, JAXB

Other ComponentsIntegrateDepend

+ Encapsulate Functionalities+ Simplify Development

StandardizationCategorize ServicesLock Up Technologies

+ Facilitates TestingComponent TestsIntegration Tests

- Difficult to DesignExperience RequiredCostly Decisions

- Obedience to StandardsCode Review

Zsolt Tóth (University of Miskolc) Component based Development 2017 6 / 30

Page 7: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Overview

3rd Party Components

ProsBoxed SolutionsGeneral TasksFaster DevelopmentReusable Components

ConsLearningDepends on Providers

Versions

Bugs!!!Support???

Logginglog4j, log4j2, slf4j

Data AccessJDBC, myBatisJPA, HibernateSpring Data

Data Conversion, MarshallingJAXB,Jackson, gson

TestingJUnitEasyMock, Mockito

Zsolt Tóth (University of Miskolc) Component based Development 2017 7 / 30

Page 8: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Interface-based Programming

Table of Contents

1 Overview

2 Interface-based Programming

3 Tools

4 Project Structures

Zsolt Tóth (University of Miskolc) Component based Development 2017 8 / 30

Page 9: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Interface-based Programming

Component Design

Divide and Conquer!

Complex tasks can be brokendownIncrease re–usabilitySimplify tasks

Separate differentprogramming languagetoolstechnologies

Zsolt Tóth (University of Miskolc) Component based Development 2017 9 / 30

Page 10: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Interface-based Programming

Interface–based Programming

Component CommunicationSeparation of

DefinitionImplementation

Decouple ComponentsLoose CouplingExchangeable Components

FacilitatesDesignDevelopmentMaintenance

Zsolt Tóth (University of Miskolc) Component based Development 2017 10 / 30

Page 11: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Interface-based Programming

Interface

Defines expected behaviorreturn typeparametersexceptionsdocumentation

Static TypeVarious ImplementationsAbstractness

/∗ ∗I n t e r f a c e Desc r i p t i on∗ /i n t e r f a c e MoneyExchangeService {

/∗ ∗Method d e t a i l s@param amount . . .@param currency . . .@return . . .@throws . . .∗ /vo id exchange (

Double amount ,Currency

currency )throws

ExchangingException ;}

Zsolt Tóth (University of Miskolc) Component based Development 2017 11 / 30

Page 12: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Interface-based Programming

Abstract Class vs Interface

SimilaritiesDesign ElementsAbstract TypesDefine Behavior

DifferencesFieldsConcrete MethodsMultiple Inheritance

Decision SupportAbstract class if:

Fields are Needed.Constructor is Needed.Concrete Method is Defined

Template Method

Otherwise Interface

Zsolt Tóth (University of Miskolc) Component based Development 2017 12 / 30

Page 13: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Interface-based Programming

Testing Dependencies

Component TestsTested SeparatelyMocking ExternalDependencies

Does the component work prop-erly, if the external dependencieswork expectedly?

Integration TestsTesting with ExternalDependenciesNo MockingTesting in "Real" EnvironmentAssume Everything isAvailable

Does the component works prop-erly in the System?

Zsolt Tóth (University of Miskolc) Component based Development 2017 13 / 30

Page 14: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Table of Contents

1 Overview

2 Interface-based Programming

3 Tools

4 Project Structures

Zsolt Tóth (University of Miskolc) Component based Development 2017 14 / 30

Page 15: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Tools – Maven

Applicationmvn <goal>Eclipse plugin

Packagingpomjarwar

PropertiesInheritance

Command Line ToolScriptsIntegration

Project Structuresrc

maintest

targetpom.xml

groupId, artifactId,version

Zsolt Tóth (University of Miskolc) Component based Development 2017 15 / 30

Page 16: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Project Object Model - pom.xmlArtifact Identification

groupId Company orProject Name

artifactId ComponentName

version Version NumberParent ProjectPackagingProperties

Build ConfigurationProject InformationDevelopment Environment

Source Code ManagementIssue TrackerMailing ListsDevelopers

<!−−Custom −−>< j u n i t . vers ion >4.12 </ j u n i t . vers ion >$ { j u n i t . ve rs ion }<!−− B u i l t −i n −−>$ { p r o j e c t . based i r }$ { p r o j e c t . vers ion }

Zsolt Tóth (University of Miskolc) Component based Development 2017 16 / 30

Page 17: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Maven Build

Source code → SoftwareCommon Task & Fix Steps

CompileClassesComponents

TestingLinkingDistribution

Automation & Toolsmakemaven, gradle, antJenkins CI

1 validate2 compile3 test4 package5 integration-test6 verify7 install8 deploy

Zsolt Tóth (University of Miskolc) Component based Development 2017 17 / 30

Page 18: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Maven Life-Cycle

Build Steps → GoalsPrevious Steps are RequiredStep Failure = Build FailureConfiguration via Plugins

Zsolt Tóth (University of Miskolc) Component based Development 2017 18 / 30

Page 19: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Maven Life-Cycle

clean

Remove target directoryvalidate

Check pom.xmlcompile

src/**.java → *.class

test

JUnit (test/**Test.java)Surefire

package

Zip to jar or warintegration-test

JUnit (test/**IT.java)verify

Check Quality Criteriainstall

Copy to Local Repositorydeploy

distributionManagement

Publishing, Sharing

Zsolt Tóth (University of Miskolc) Component based Development 2017 19 / 30

Page 20: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Maven Dependency Management

Other Component3rd Party LibraryOther Part of the System

Deployed ArtifactStored in RepositoryAutomatic

SearchDownloadAdding to ClassPath

<dependency><groupId >

org . apache . logg ing . l o g 4 j</ groupId >< a r t i f a c t I d >

l o g 4 j</ a r t i f a c t I d ><vers ion >

2 .8 .2</ vers ion >

</dependency>

Zsolt Tóth (University of Miskolc) Component based Development 2017 20 / 30

Page 21: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Repositories

Zsolt Tóth (University of Miskolc) Component based Development 2017 21 / 30

Page 22: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Maven Central & Company’s Private Repositories

Maven Central RepositoryKnown Locationwww.maven.org

PublicLibraries

FreeCommon Tasks

Private RepositoryProxyOur Precious ProductsKept in Secret

LANVPN

Zsolt Tóth (University of Miskolc) Component based Development 2017 22 / 30

Page 23: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

Local Repository $HOME/.m2/

Maven ConfigurationsUsed DependenciesKnown Location

repository directorysettings.xmlsecurity-settings.xml

Stored LocallyDownloaded OnceShared Among Projects

repository+--org/apache/logging|+--log4j/log4j-core||+--2.2||\log4j-core-2.2.jar||\log4j-core-2.2.pom||+--2.5||\log4j-core-2.5.jar||\log4j-core-2.5.pom||+--2.6.2||\......

Zsolt Tóth (University of Miskolc) Component based Development 2017 23 / 30

Page 24: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Tools

settings.xml

Developer’s SettingsShared Among ProjectsServer Access

username, passwordEncryptionsecurity-settings.xml

ProfilesBuild SettingsConditions

OSJDK Version

Properties

< s e t t i n g s xmlns=" . . ">< loca lRepos i t o r y / >< in te rac t i veMode / ><usePlug inReg is t ry / >< o f f l i n e / ><pluginGroups / ><servers / >< m i r ro r s / ><prox ies / >< p r o f i l e s / >< a c t i v e P r o f i l e s / >< / s e t t i n g s >

Zsolt Tóth (University of Miskolc) Component based Development 2017 24 / 30

Page 25: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Project Structures

Table of Contents

1 Overview

2 Interface-based Programming

3 Tools

4 Project Structures

Zsolt Tóth (University of Miskolc) Component based Development 2017 25 / 30

Page 26: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Project Structures

Project Structures

No Silver Bullet

Depends onCompanyArchitectProject RequirementsCompetenceLazinessetc.

Defined bySoftware ArchitectsSenior Developers

Should be Considered:Functionalities based on

Users / RolesCommercial UnitsReusability

TechnologiesProgramming TechniquesProgramming Languages

Build and Testings

Zsolt Tóth (University of Miskolc) Component based Development 2017 26 / 30

Page 27: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Project Structures

Example Project Structure #1

Zsolt Tóth (University of Miskolc) Component based Development 2017 27 / 30

Page 28: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Project Structures

Example Project Structure #1util

Utility FunctionsLogging ConfigurationDo not Fit Elsewhere

model

Domain ModelLow Level Validation

persist

Data Access ObjectInterfaces

persist-*

DAO ImplementationDepends on Technology

service

Service DefinitionInterfaces

service-impl

Service Implementationcontroller

Entry Point of the ComponentValidate & Sanitize

DiscussionPros and Cons ?Why?

Zsolt Tóth (University of Miskolc) Component based Development 2017 28 / 30

Page 29: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Project Structures

Example Project Structure #2

Zsolt Tóth (University of Miskolc) Component based Development 2017 29 / 30

Page 30: Web Application Development Zsolt Tóthusers.iit.uni-miskolc.hu/~tothzs/edu/webdev/component... · 2017. 8. 24. · Eclipse plugin Packaging pom jar war Properties Inheritance Command

Project Structures

Example Project Structure #2

core

Domain ObjectsValidation

Service DefinitionInterfaceException

service

Service ImplementationDAO General Definition

InterfaceException

DAO

Multiple ImplementationsTechnology Dependent

web

Entry Point of ComponentDeployable

DiscussionPros and Cons ?Why?

Zsolt Tóth (University of Miskolc) Component based Development 2017 30 / 30