Component-Based Software Engineering ECE493-Topic 5 Winter 2007 Lecture 18 Enterprise Styles/Patterns (Part A) Ladan Tahvildari Assistant Professor Dept. of Elect. & Comp. Eng. University of Waterloo Basic Properties of Styles A vocabulary of design elements Component and Connector types (pipes, filters, clients, servers) A set of configuration rules Constraints that determine allowed compositions of elements (a component may be connected to at most two other components) A semantic interpretation Compositions of design elements have well-defined meanings Explanation of what components are supposed to do in general Explanation of how connections are meant to work 2
From Abstractions to Implementations Abstract views (platform independent, Written in UML) Abstract system architecture Architectural Styles Pipes and Filters 2-Tiered N-Tiered Layered Blackboard Model View Controller Domain-specific Models (Platform specific, Written in UML with extra notation) Enterprise Middleware Architecture Safety Critical Architecture Embedded System Architecture Implementations OO: simple Java:.NET: EJB, COM+, CORBA C JMS, JSP ASP 3 COM+ Services = Basic Enterprise Styles Each of the COM+ services constitutes a style itself, consisting of component kinds, constraints and uses If we were to design an abstract architecture, and were ignorant of COM+, we might need to provide a lot more detail to specify such styles. how would you specify transactions as a style? The task of applying a COM+ service style to system architecture is essentially one of understanding what service is appropriate for what context 4
COM+ Services as Styles Service Transactions Object pooling JIT Activation Queued Components Loosely Coupled Events Components & Constraints Business logic components. Client components, server (pooled) components Pooled components cannot hold state or have thread affinity Client and server components Client, server components. Queued interface cannot return values nor take input by reference Publisher, subscribers, event component Event component does not implement its interface, shares the same provided interface as server Use Recovering from errors Ensuring business processes complete successfully as a group Whenever server component is fat and expensive to create for clients Whenever server is thin but often idle Sometimes disconnected client components Prioritizing non-critical tasks through queues Anonymous communication between publishers and subscribers Need to ensure open scalability to new subscribers 5 Complex Enterprise Styles Complex enterprise styles involve the combination of enterprise services to achieve a range of goals Styles built for integration specifically within an n-tiered architecture Sometimes combinations or configurations of services can have negative impact on performance, reliability, etc Platform-specific constraints are sometimes necessary to avoid this Most important complex enterprise styles involve interaction with other tiers of the architecture Let s quickly look at the available technologies for these tiers 6
Web Services Problem: Various systems require integration Written under heterogeneous platforms and languages Distributed over a network (possibly the internet) Solutions: Re-implement systems to operate under a common platform or communication framework (costly) Implement connection points between systems as Web Services (cheaper) Java Based System Web Service Web Service Client HTTP SOAP Web Service Client Web Service.NET Based System 7 Web Services: Concepts An easy and flexible way of doing RPCs Web Services are components whose interfaces are exposed through HTTP A client component obtains a proxy reference to the web service and invokes methods on that Web services infrastructure transforms method invocations into XML for transmission over the net to the web service, using the Simple Object Access Protocol and HTTP. 8
UML2 Specialization Define a stereotype <<Webservice>> to denote that a component is considered a.net implemented webservice Tagged attributes to denote the location of the service (WebServiceNamespace) define which methods of the provided interface are exposed as part of the web service (WebMethod) these attributes are associated with provided interface If a client component is connected to a webservice, it is understood to communicate to the service through SOAP do not specify this other than through connection to the webservice Webservice components can require functionality through provided interfaces whether this is to be given through SOAP or through some other.net form of communication is left open until a connection is specified 9 Web Services in.net Very easy to program in.net writing as ordinary classes, inheriting from the WebService superclass to specify that the class defines a webservice custom attributes providing metadata about where the service is located on the web and what methods are to be exposed: using System; using System.Web.Services; using System.Xml.Serialization; [WebService(Namespace="http://localhost/MyWebServices/")] public class ExampleService : WebService { [WebMethod] public int Add(int a, int b) { return a + b; } } [WebMethod] public String SayHello() { return "Hello World"; } 10
.NET Enterprise Services (COM+) Middleware are based around the principle that an n-tiered style is the structural idiom for building enterprise systems. COM+ is built to house business-logic components within a middle tier other middleware must be chosen to develop presentation and data tiers. ASP.NET (Presentation tier) COM+ (Business logic tier) DB (Data tier) 11 Presentation Tier ASP.NET Active Server Pages (ASP) are a server-side scripting environment that can be used to create dynamic web pages or build web applications ASP pages are files that contain HTML tags, text and script commands ASP pages can then call COM+ components or web services to perform tasks, such as connecting to a database or performing business operations ASP has been around for a while now The Most Significant Improvement: scripts are now compiled on the server side and can be reused multiple times 12
UML2 Specialization We represent ASP pages as components with an <<ASP>> stereotype From an architectural perspective, ASP pages are HTML pages that can call other ASPs and components from other tiers Functional dependencies on other components are represented by required interfaces ASP pages have two kinds of provided functionality: They provide functionality to a human user (not represented here) They provide functionality that can be used by other ASPs (e.g., by requests and responses) this functionality is represented as a provided interface 13 N-Tiered Enterprise Styles Enterprise applications are almost built around a 3-Tiered Style, with some form of middleware handling business-logic tier components. Example:.NET COM+: Business-Logic Middleware ASP.NET: Presentation Tier Technology DB: Data Tier Enterprise styles are just like ordinary styles, but with components taken from the chosen enterprise modelling language Enterprise specific styles address concerns specific to this domain Sometimes combinations or configurations of services can have negative impact on performance, reliability, etc Platform-specific constraints and semantics are necessary to avoid this. 14
Key Concepts What kind of styles are most important here? Styles for maintaining the demarcation of purpose between the tiers presentation kept separate from business logic Styles for ensuring efficiency of communication between tiers Styles that require constraints on presentation tier: View Helper Front/View Controller Business Delegate Styles that require constraints on business logic tier: Session Façade Coarse Grain Interfaces 15 Example 1 Context The system creates presentation content through ASP views, which perform processing and coordination of data obtained from business logic components These two views use a COM+ component to perform authentication lecturer and student users before providing access to the school s timetabling system both ASP pages include separate code to perform authentication before displaying timetable information <<ASP>> Lecturer <<COM+>> Authentication <<ASP>> Student <<COM+>> ExamTimeTabling 16
Example 1: Problems Common system logic is embedded in a range of.asp views. This causes maintenance problems and bugs because a piece of logic is reused in the same or different view by simply cutting and pasting it. Presentation tier can change often difficult to develop and maintain when business data access logic and presentation formatting logic are interwoven. Intermingling business logic with view processing reduces modularity and also provides a poor separation of roles among Web production and software development teams. Potential Solution: It is desirable to promote a clean separation by having different individuals fulfill the roles of software developer and Web production team member. 17 Style 1: View Helper Introduce intermediate view helper components, implemented as ASPs Helpers also store the view's intermediate data model and serve as business data adapters View helpers are implemented as pagelet ASPs pagelet ASPs are never directly called by end users, only by other ASPs ASPs are used as a means to componentized presentation logic for reuse Multiple views may leverage the same helper to retrieve and adapt similar model state for presentation in multiple ways 18
Example 1: Solution <<ASP>> Lecturer <<ASP>> Authenticated ExamTimetabling <<ASP>> Student Intermediate view helper ASP runs at the presentation tier, encapsulates logic to do with authorized access to restricted information common to lecturer and student ASPs. <<COM+>> ExamTimetabling <<COM+>> Authentication 19 Enterprise Styles Styles that require constraints on presentation tier: View Helper Front/View Controller Business Delegate Styles that require constraints on business logic tier: Session Façade Coarse Grain Interfaces 20