Software Engineering I Notes for Sept 17, 2012 Reuse - i.e. making design and code reusable Types of reuse - Expertise - don't need to rethink some issues - Standard design and algorithms - books, standards, algorithms +Follow to implement - Libraries, classes, procedures, OS/Language Commands - Frameworks - libraries containing structure of entire applications or subsystems - Full applications How to incorporate? - Self initiated - Encourage through management - Don't rush development - Consider long-term vs. short-term payoff Be sure to deprecate poor components Framework - reusable software with a generic solution to a general problem -Typically incomplete -Missing parts are often called _slots_ -Slots must be filled in - _Hooks_ are like soltions but are optional functionality API - Application Program Interface -A set of services provided by a framework -Ex: Payroll, frequent buyer club, course registration, e-commerce sites Product Line - set of products built on common base of technology e.g Microwaves, Stoves, TVs, etc. Commmon framework e.g Pro vs Lite Horizontal vs. Vertical Framework Horizontal supports many applications (more general) Horizontal Framework +-------------+ | App | | +---+ +---+ | | |+-+| |+-+| | +-+ +-+ +-+ +-+| |+-+| |+-+ | | | | | | +----+ +---+ +------+ +---+ +---+ +---+ | Slot Slot Slot Slot Slot | | Hook | | +---+ +---+ +-+-+ +---+ +---+ | | |+-+| |+-+| | ) | | | | | | | || || || || | | | | | | | +----+| |+-+| |+-+ +-+ +-+ +----+ +--+ +---+ +--+ | App 2 | +-------------+ Vertical Framework +-------------+ | App | | +---+ +---+ | | |+-+| |+-+| | +-+| |+-+| |+-+ +----+ +---+ +-----+ | Slot Slot | | | | +---+ +---+ | | |+-+| |+-+| | | || || || || | +----+| |+-+| |+---+ +--+ +---+ +--+ | App 2 | +-------------+ Example types of frameworks OO Frameworks - library of classes Defined by public methods of public classes Ex: Hadoop, Java API, Jasper, Apache POI Read about these...I might ask a question about them. Client-Server Architecture Preliminaries SW Architecture deals with the organization and connection of modules so they can work together. Think about a _distributed_system_ where computations are performed by separate programs. Server - program that provides service for other programs that connect to it using a communication channel Client - program that accesses a server -May access many servers Client-server system - a distributed system involving at least one client and one server. Peer-to-peer - programs that can act as both client and server. How it works 1. server starts 2. Server waits for clients (listens) 3. Clients run and perform operations to try to connect to and request service from the server. 4. Server accepts communication if it is willing. 5. Waits for messages from clients. 6. Server responds to messages and then waits 7. Eventually, the server shuts down. Examples of Client-Server architecture are everywhere. www, email, Transaction processing, remote displays, databases, communications systems, NFS UML Sequence Diagram +---------+ +----------+ +------------+ | Server: | | Client1: | | Client2: | +---+-----+ +----+-----+ +-----+------+ | | | | | | | | | +-+ | | | |-------+ | | | Listen for comm. | | | |<------+ | | Connect +-+ | | |<-----------------------------| | | | Send Message | | +-+ | |<-----------------------------| | Connect | | | |<----------------------------------------------------| | | | Send Reply | | | | | |----------------------------->| | | | | | Disconnect | | | | | |<-----------------------------| | | | | | +-+ | | | | Send Message | | | |<----------------------------------------------------| | | | Disconnect | | | |---------------------------------------------------->| | | |-----+ +-+ | | | Stop listening | |<----+ +-+ Alternatives to the client server are possible. Why is client server useful? -can be distributed -design of modules can be done separately -data storage can be centralized or distributed -geographical distribution is possible Server Design - self initialization - able to start listening for client - able to handle events from clients + Accept connections from clients -Should validate and keep track of connection while client is connected. + React to messages from clients connected to server + Handle disconnections (forced or requested) - Stop listening + Don't accept new clients + Too many connections + Too few resources - Clean termination Client design -self initialization given address of server -initiate connection and retry -send messages and request services -react to messages from server -clean termination Server UML States +--------------------------------+ +----+ | +-------+ |terminate *-->|Init|-->| *--->|waiting| |--------->(*) +----+ | +-------+ | | start | ^ stop listening | |listening| | | | V | | | +------------------------+ | | | Wait for communication | | | +------------------------+ | | | ^ accept communication | | +---+ | +--------------------------------+ For each connection +------------------+ * ---------->|Handle Connection |---->(*) |React to messages | +------------------+ Client UML States +------+ +---------------------------+ *------>| Init |-------->| Init. connection to server| +------+ +-------+-------------------+ | V ---+--------------------------------------------------+--- | | V V +-------------------------------+ +------------------------------+ | Interact with user, sending | | Respond to events triggered | | messages to server as needed | | by server such as messages | +-------------------------------+ | and handle server disconnect | | +------------------------------+ | | V V ---------------+-------------------- | V +-----------+ | Terminate |--->(*) +-----------+