Block V Unit 2 Components Patterns and Architectures

Block V – Unit 2 Components, Patterns and Architectures AOU Beirut Computer Science M 301 Block V, unit 2 1

Section 1 Components and Component based Development AOU Beirut Computer Science M 301 Block V, unit 2 2

Requirements for an ideal Component n Have a number of interfaces , each named and defined separately. n Each interface consists of a coherent set of operations (called signature). n Two kinds of interface: n n Those that are provided by a component for use by other components (provided interfaces) And those that are required from other components for use by the component required interfaces). n All of a component’s interfaces must be public. This idea, that a component can only be used through its public interfaces, is known as encapsulation. n No knowledge of the internal workings of a component can be used (known as information hiding). AOU Beirut Computer Science M 301 Block V, unit 2 3

Requirements for Component Interconnection n n Components can be interconnected to create a larger assembly or supercomponent. The signatures of the interfaces that are connected together must match, i. e. they must have the same operations with the same input and output arguments (principle of substitutability). n Some interfaces can be internal to the supercomponent, and so are not visible from outside the supercomponent, n Other interfaces are made external, and so are visible from outside the supercomponent. n Additional ‘glue’ can be inserted between components to enable simple conversions to be made in order to match interfaces that are not identical. AOU Beirut Computer Science M 301 Block V, unit 2 4

Components and their Interconnection AOU Beirut Computer Science M 301 Block V, unit 2 5

Object Oriented Components in Java n Components in OOL have gaps. n n A component (such as a class) may only be able to provide a single (provided) interface. Required interfaces do not need to be made explicit. n Non-object-oriented languages have further severe limitations in encapsulation and information hiding. n Object-oriented languages do at least give very strong encapsulation. n Java, along with other object-oriented languages, makes strong claims about supporting the reuse of components (next) -. AOU Beirut Computer Science M 301 Block V, unit 2 6

Code Reuse with Java n Inheritance as one mechanism for reuse: n Specialization: n Specification: n Construction: the child class is a subtype of the parent class, a relationship which makes sense in terms of abstract concepts and not just in terms of code. the parent class defines behaviour that is implemented in the child class, via interfaces or abstract classes. the child class uses the behaviour coded in the parent class, but does not create a subtype. n Extension: n Limitation: n Combination: the child class adds functionality to the parent class but does not change any inherited behaviour. the child class restricts the use of some of the inherited behaviour. the child class inherits features from more than one parent class, by inheritance and implementation of interfaces. 7

Java Classes as Components n n Classes in Java give most of what is wanted for components. Classes give encapsulation and information hiding, with the provided interface being very explicit: n n In Java, methods and data can be declared as public, or private and only visible locally within the class, or protected and visible locally within a package. The public part of the class can be described separately either using the interface construct or by using the abstract construct. AOU Beirut Computer Science M 301 Block V, unit 2 8

Java. Beans n Java. Beans are Java classes that provide 5 capabilities making them reusable and useful in production systems: n Self-describing: n Storing reusable classes: n Incorporating: n Persistence: n Distribution: either through a specification of the class or through introspection (feature interrogation). with good search facilities to find classes of potential use. easy ways of incorporating an existing component into an emerging design, making the connections as required. Java objects and their states are preserved over long periods of time, perhaps as parts of a database. Java objects may communicate with other objects when distributed over many processors connected together by communication networks. AOU Beirut Computer Science M 301 Block V, unit 2 9

Enterprise Java Beans (EJB) n EJBs have more facilities that aid the development of very large distributed systems. These facilities are as follows: n Have separate interface ‘views’ for users of the EJB components. n Have two types of persistence: n n n Session persistence occurs when software is executed for a short time, called a session. EJBs need only persist for the session. Entity persistence occurs when the EJB persists over many sessions. There are containers that control the creation and execution of EJBs: n n User is only able to see the interface view of the EJB in the container. Container hides all the ‘plumbing’ of transactions, protocols, security, and interprocessor communication. AOU Beirut Computer Science M 301 Block V, unit 2 10

Using Components n To use a component, one must: n n The last one is typically: n n Search for a suitable component (e. g. repository). Adapt our component to use the component we are looking for. Paying for the component (if commercial product). Less expensive than developing a component. More reliable (tested by different users). High quality (developed carefully, tested thoroughly for widespread use). However well a component has been tested, and however widely it has been used, this may not provide any basis for confidence in using the component in a new context (e. g. Ariane 5 failure) AOU Beirut Computer Science M 301 Block V, unit 2 11

Using Components n n How are components supposed to be used? An early idea from around 1980 was to build a repository of useful components: The use of a component repository can be formalized into a process model, which consists of two parts, as illustrated in Figure 1. 2. AOU Beirut Computer Science M 301 Block V, unit 2 12

Using Components n How could a component repository be organized to make it easy to find the component you required? n Each component is assigned a number of descriptive terms n Classified terms are those constrained - chosen from a fixed repertoire of possible terms. n n Keyword terms: unconstrained Faceted classification: which is a method used for building indexes for library books. Each component within a facet is further classified by associating keywords with it. AOU Beirut Computer Science M 301 Block V, unit 2 13

Difficulties with Component Reuse n Finding a relevant component in the first place: n n Need to control further development: n n n Will new versions be moving in the direction that we want? Does the component include a lot of other things we don’t need? Responsibility for maintaining the imported component: n n Do components do what we want? How much do we trust the component’s author? Finding generalized components with documentation: n UML diagrams showing the tasks supported by the component. AOU Beirut Computer Science M 301 Block V, unit 2 14

Making reuse happen AOU Beirut Computer Science M 301 Block V, unit 2 15

Section 2 Architectures, Frameworks and Product Lines AOU Beirut Computer Science M 301 Block V, unit 2 16

Software Architecture n n Software architecture is a high level abstract view of software. Architectural styles is a way the subsystems interact and are connected. n Data-flow: system. to support reuse and modifiability. Focuses on the flow of data through the n Data-centred: to support the ability to integrate systems sharing data Virtual-machine: to supportability; this style can be used in layered architectures Call–return: to support modifiability and scalability. Focuses on the sequence of n Independent-components: n n computation and synchronous communication. to support modifiability AOU Beirut Computer Science M 301 Block V, unit 2 17

Application Architecture n The application architecture of a system is the specification model, consisting of: n n n High-level use case diagrams Class diagrams Related activity and interaction diagrams. n Conceptual model = first architectural model n Specification model = full architectural model AOU Beirut Computer Science M 301 Block V, unit 2 18

Frameworks n n n Architectural models of different systems have aspects in common. Chunks of architecture that can be reused in this way are usually called frameworks. Each framework would be accompanied by suitable code that could be used with the framework. n n n Part of this code would be for the framework itself, but most of the code would be for components that could be slotted into the framework. Each framework would be accompanied by suitable documentation to facilitate its use. AOU Beirut Computer Science M 301 Block V, unit 2 19

From Framework to Product Line n It is not easy to generate a framework: n n n The generic frameworks evolves over many years of experimentation and industrial experience. They depend upon a lot of supporting software. When a company wants to produce a range of products based on a common framework it is a called product line. n n For example, the company producing the hotel system in Block 4 might want to produce a range of systems for the hospitality industry. Product lines are a very effective approach to software development. AOU Beirut Computer Science M 301 Block V, unit 2 20

Product Line Process n Product lines are built upon the idea of frameworks. n There a number of steps that are undertaken: n Product-line initiation: n Domain analysis: n Architecture specification: n Component collection: a class of commonly recurring software systems where solutions do not differ much from each other. a form of requirements elicitation leading on to general models of data and process (e. g. conceptual model of use case and class diagrams). line. Further analysis that lead to the architecture for the product as with a framework, each architecture will be accompanied by a repository of candidate components that could be used in the architecture. AOU Beirut Computer Science M 301 Block V, unit 2 21

Product Line Process n n Three further steps are required, each of which must be repeated for each new product in the line. n Specific-requirements capture: n Architecture specialization: n Component selection and specialization: requirements for a new product are captured, as specializations and extensions of the domain model. a reference architecture is selected based on the specific requirements, and changes are made to incorporate the corresponding specializations and extensions of the domain model. The product that meets the new requirements is then built, selecting components from the repository where these exist, and adapting them as necessary. The final step is the following: n Integration and release: of the components into the architecture should be relatively easy — if the architecture has been well designed. AOU Beirut Computer Science M 301 Block V, unit 2 22

Section 3 Patterns AOU Beirut Computer Science M 301 Block V, unit 2 23

MVC Architecture - Example n Suppose that you want to build a personal budgeting system that allows you to plan the way you will use your money. n n It should allow you to set a number of budget headings, Then It should allow you to record under each the sum of money you are allocating — either the absolute amount or as a percentage of your income. The allocations should be capable of being displayed in a bar chart, in a pie chart or as a spreadsheet. These requirements are illustrated in Figure 3. 1. AOU Beirut Computer Science M 301 Block V, unit 2 24

MVC Architecture - Example AOU Beirut Computer Science M 301 Block V, unit 2 25

MVC Architecture - Example AOU Beirut Computer Science M 301 Block V, unit 2 26

MVC Architecture - Example AOU Beirut Computer Science M 301 Block V, unit 2 27

MVC Architecture - Example AOU Beirut Computer Science M 301 Block V, unit 2 28

MVC Architecture – Design Patterns n Architectures like MVC are sometimes called architectural patterns n n n high-level solutions encompassing the complete problem. There a number of different kinds of pattern: n Architectural patterns, n design patterns, n analysis patterns, n process patterns, and even n Business patterns. Most research and development of patterns has gone into design patterns. AOU Beirut Computer Science M 301 Block V, unit 2 29

Design Patterns n Buschmann talks about patterns existing at several levels: n n n Architectural patterns are at the highest level, such as MVC. Design patterns are the intermediate level pattern, such as the Observer pattern, described below. Idioms are at the lowest level and include program code level concepts such as the swap pattern: n temp : = a, a : = b, b : = temp. AOU Beirut Computer Science M 301 Block V, unit 2 30

Design Patterns n One of the attractive things about design patterns is that they are not prescriptive: n n n you can take them or leave them, you choose to use them only if they benefit your design or some other activity. To help you select a pattern, it is normal to catalogue them using a fixed format: n Name, motivation, applicability or context, problem, solution, collaborations or dynamics, participants, consequences, implementation, sample code, variants and related patterns, known uses. AOU Beirut Computer Science M 301 Block V, unit 2 31

Pattern catalogue n n n n Name: alternative names in use. Motivation: why the pattern is useful and important. Applicability or context: the situations in which the pattern can be applied. Problem: the actual design problem that the pattern addresses. Solution: the principles involved in solving the problem. Structure: the class diagram. Collaborations or dynamics: one or more interaction diagrams. AOU Beirut Computer Science M 301 Block V, unit 2 32

Pattern catalogue n n n Participant: textual definitions of the object classes involved. Consequences: any trade-offs involved. Implementation: any pitfalls you might meet, or special techniques you might use. n n Sample code: code fragments to help the implementation. Variants and related pattern: similar patterns and specializations of this pattern. n Known uses: such as reference sites. AOU Beirut Computer Science M 301 Block V, unit 2 33

Observer or Publisher-Subscriber Pattern n Motivation: MVC architecture, in particular the way views and controllers are both connected to the model and observe it. n n The model has an attribute for each set of attached objects (views, controllers) and sends a message whenever the model’s state is updated. Views and controller can be generalized to form an abstract class Observer, which wants to be kept informed about the changes in state of some other class Subject. n Applicability or context: n Problem: n Solution: n Structure: a system has a number of parts which must be synchronized (different presentations of data to a user). several objects (Observers) need their states to be kept synchronized with the state of some other object (Subject). Register the Observers with the Subject, so that each time the Subject’s state changes, it notifies the Observers, which then ask the Subject for its state. this leads to the class diagram in Figure 3. 5. AOU Beirut Computer Science M 301 Block V, unit 2 34

Observer Structure AOU Beirut Computer Science M 301 Block V, unit 2 35

Observer Collaborations AOU Beirut Computer Science M 301 Block V, unit 2 36

Observer Consequences n Consequences: n n Coupling between an Observer and the Subject is minimal, and Coupling between Observers is nonexistent, which enables Observers to belong to quite different parts of the system. The full cost of the change of state of a Subject might be large, but is masked by the low coupling and is difficult to anticipate. Variants and related patterns: n Instead of the Subject just notifying the Observers, it could also send its full state, saving them the need to request it themselves. AOU Beirut Computer Science M 301 Block V, unit 2 37

The Factory Pattern n Motivation: MVC architecture; a number of concrete classes must be developed: n one concrete application, n one concrete model and n several different concrete views, with their corresponding concrete controller. n Problem: n Solution: at the abstract level of a framework, a Creator class creates an instance of Product class, but the actual concrete subclass to be created is not known by the abstract Creator class, only by its concrete subclass. have an abstract method in the Creator class that is redefined in the concrete Creator subclasses. AOU Beirut Computer Science M 301 Block V, unit 2 38

The Factory Pattern - Structure AOU Beirut Computer Science M 301 Block V, unit 2 39

The Factory Pattern - Collaboration AOU Beirut Computer Science M 301 Block V, unit 2 40
- Slides: 40