Docsity

Software Architecture, Lecture notes of Software Development Methodologies

Partial preview of the text

Download Software Architecture and more Lecture notes Software Development Methodologies in PDF only on Docsity!

“A SKELNCT Sa ee at ation for Execution” 7 SOFTWARE ARCHITECTURE LAB MANUAL Sr. | Title of experiment Page No. No. Lot Study report of any two design patterns, 2. _ _Implemeniation of any two design patterns in java. : - Study report for any of the MVC based Frameworks (J2EE). at 4. Study report on EJB. 2. implementation of a web application for a system covering representative paper design of the system using navigation, components, interfaces, its deployment issue with UML, 6. A) Develop dynamic and interactive web client using JSP, Scripting/Applets/ActiveX controls, B) Develop server side programming with database handling/ servlets/EJB/webservice on server side with security aspects covered. 4) SKC Lakshmi Narain College of Technology, Indore SRoUP OF COLLEGES mn for Execution” Assignment Number: 01 Title: Study report of any two design patterns. Aim: Study report of any two design patterns. Objective: To study of Design Patterns . Theory: What is a Design Pattern? Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. Our solutions are expressed in terms of objects and interfaces. Design Pattern is general reusable solution to commonly occurring problems. In general, a pattern has four essential elements: 1. The pattern name is a handle we can use to describe a design problem, its solutions, and consequences in a word or two. Naming a pattern immediately increases our design vocabulary. It lets us design at a higher level of abstraction. Having a vocabulary for patterns lets us talk about them with our colleagues, in our documentation, and even to ourselves. It makes it easier to think about designs and to communicate them and their trade-offs to others. Finding good names has been one of the hardest parts of developing our catalog. } 2. The problem describes when to apply the pattern. It explains the problem and its context. It might describe specific design problems such as how to represent algorithms as objects. It might describe class or object structures that are symptomatic of an inflexible design. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern. 3. The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations. The solution doesn't describe a particular concrete design or implementation, because a pattern is like a template that can be applied in many different situations. Instead, the pattern provides an abstract description of a design problem and how a general arrangement of elements (classes and objects in our case) solves Page 2 SKC Lakshmi Narain College of Technology, Indore y > SKCLNCT ae n for Execution” Create interfaces. Hteratorjava public interface Iterator { public boolean hasNext(); public Object next(); } Container java public interface Container { public Iterator getlterator(); } Step 2 Create concrete class implementing the Container interface. This class has inner class Namelterator implementing the Iterator interface. NameRepositoryjava public class NameRepository implements Container { a) public String names[] = {"Robert" , "John" ,"Julie" » "Lora"}; : @Override public Iterator getlterator() { return new Namelterator(); } private class Namelterator implements Iterator { int index; @Override public boolean hasNext() { iftindex < names. length) { return true; } return false; } @Override public Object next() { if(this.hasNextQ){ ) return names[index++]; ; } return null; } } } Step 3 Use the NameRepository to get iterator and print names, Page 4 SKC Lakshmi Narain College of Technology, Indore > ‘KOLNCT iBUP OF COLLEGES i for Execution” oe HteratorPatternDemo java public class IteratorPattemDemo { public static void main(String[] args) { NameRepository namesRepository = new NameRepository(); for(Iterator iter = namesRepository.getlterator(); iter.hasNextQ);){ String name = (String)iternextQ; System.out.printin("Name : " + name); ' } } } Step 4 Verify the output. Name : Robert Name : John Name : Julie Name : Lora ) Mediator Pattern: Mediator pattern is used to reduce communication complexity between multiple objects or classes. This pattern provides a mediator class which normally handles all the communications between different classes and supports easy maintainability of the code by loose coupling. Mediator pattern falls under behavioral pattern category. | Intent Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. Motivation Object-oriented design encourages the distribution of behavior among objects. Such distribution can result in an object structure with many connections between. [) objects; in the worst case, every object ends up knowing about every other. Though partitioning a system into many objects generally enhances reusability, proliferating interconnections tend to reduce it again. Lots of interconnections make it Jess likely that an object can work without the support of others—the system acts as though it were monolithic. Moreover, it can be difficult to change the system's behavior in any significant way, since behavior is distributed among many objects. As a result, you may be forced to define many subclasses to customize the system's behavior. Implementation Page SKC Lakshmi Narain College of Technology, Indore rea “SKELNCT 1e Jf yf. JORDUP OF COLLEGES on for Execution’ public static void main(String[] args) { User robert = new User("Robert"); User john = new User("John"); tobert.sendMessage("Hi! John!"); john.sendMessage("Hello! Robert!"); } } Step 4 Verify the output. Thu Jan 31 16:05:46 IST 2013 [Robert] : Hi! John! Thu Jan 31 16:05:46 IST 2013 [John] : Hello Conclusion: Thus We have studied two design patterns(Iterator and mediator design pattern). Page Assignment Number: 02 Title :_ Implementation of any two design patterns in java . Aim: Implementation of any two design patterns in java. Objectives: To study implementation of 1) Observer Pattern.2)Singleton pattern Theory: Observer Pattern; Observer pattern is used when there is one to many relationship between objects such as if one object is modified, its depenedent objects are to be notified automatically. Observer pattern falls under behavioral pattern category. Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Also Known As Dependents, Publish-Subscribe Motivation A common side-effect of partitioning a system into a collection of cooperating classes is the need to maintain consistency between related objects. You don't want to achieve consistency by making the classes tightly coupled, because that reduces their reusability. For example, many graphical user interface toolkits separate the presentational aspects of the user interface from the underlying application data Classes defining application data and presentations can be ) Reused independently. They can work together, too. Both a spreadsheet object and : bar chart object can depict information in the same application data object using different presentations. The spreadsheet and the bar chart don't know about each other, thereby letting you reuse only the one you need. But they behave as though they do. When the user changes the information in the spreadsheet, the bar chart tefiects the changes immediately, and vice versa. Page ss SKC Lakshmi Narain College of Technology. Indore | - Teewe of Jechnologv. Indore | ‘KCLNCT vide OF EDLLEGES 1 for Execution ~~, b lic yoid notifyAllObservers(){ for (Observer observer : observers) { observer.update(); } } } Step 2 Create Observer class. Observerjava public abstract class Observer { protected Subject subject; public abstract void update(); } Step 3 Create concrete observer classes BinaryObserver java public class BinaryObserver extends Observer{ public BinaryObserver(Subject subject){ this.subject = subject; this.subject.attach(this); } @Override public void update(Q) { System.out.printIn( "Binary String: “ + Integer.toBinaryString( subject.getState() ) ); } } OctalObserver java public class OctalObserver extends Observer{ public OctalObserver(Subject subject) { this.subject = subject; this.subject.attach(this); } @Override public void updateQ) { System.out.printIn( "Octal String: " : Integer.toOctalString( subject.getState() ) ); } Page 10 SKC L i Narai Nn CLNGI pe OF COLLEGES Execution a : gObserverjava role class HexaObserver extends Observer { public HexaObserver(Subject subject) { ld this.subject + subject; this subject.attach( this); @override public void update() { : gystem.out.printin( "Hex String: + Integer.toHexString( subject.getStateQ) ),toUpperCase() ); } } Step 4 Use Subject and concrete observer objects. ObserverPatternDemojava public class ObserverPatternDemo { public static void main(String[] args) { ; Subject subject = new Subject); 7) new HexaObserver(subject); : new OctalObserver(subject), new BinaryObserver(subject); System.out.printhi("First state change: 15"); subject.setState(1 5); System.out.printin("Second state change: 10"); subject.setState(10); } } Step 5 Verify the output. First state change: 15 Hex String: F Octal String: 17 Binary String: 1111 Second state change: 10 Hex String: A Octal String: 12 Binary String: 1010 wy Si : Sing leton pattern is one of the simplest desig n patterns in Java. T his type of desig n pattern comes under creational pattern as this pattern provides one of the best way to create an object. Page 11 SKC Lakahinl Narain College of Technology, Indore | -~ sansom Nara: 7 NL Le Coll Ti di lore 5 We have implemented two design patterns(Observer and Adapter design pattern). us enignmaent Number: 03 dy report for any of the MVC based Frameworks Title: Stu Aim: Study report for any of the MVC based Frameworks Objectives: To study MVC Architecture. Theory: Introduction: i The ever-evolving Java programming language and Sun's J2EE specification have enabled software developers of various disciplines to create distributed computing applications that were previously possible only with relatively proprietary tools. Thus, while some development teams may choose to implement new systems in the Java platform, others will create, enhance, and maintain applications using other skills and then integrate them into an existing heterogeneous distributed application. This situation gives rise to an interoperability challenge. How can a new application interact with an old one? The answer: web services. Web services are the new holy grail of programming. They make it possible to share and coordinate dispersed, heterogeneous computing resources. MVC Architecture Seperates business logic from representation of information. The MVC design pattern clearly demarcates the roles of programmers and designers. In other words, it separates data from business logic. This pattern allows designers to concentrate on the display portion of an application and developers to concentrate on developing the components required to drive the application's functions. MVC is used to separate logic into 3 distinct units:1]The Model 2)The View 3]The Controller MVC Architecture: An application's data models (the Model), presentation code (the View), and program control logic (the Controller) should exist as distinct but intercommunicating components. The Model component represents and processes application data. The View Page 13 SKC Lakshmi Narain College of Technology, Indore erface; it reflects the Model data and Presents it to the user. The Controller tions performed on the View (for example, pressing a Submit button) to maps ac! on the Model (for example, retrieving user details). After the Model is operon View is refreshed and the user can perform more actions. The MVC pattern updated, de and facilitates code reuse; in addition, in many projects the View is pg ryrapdite d, and the MVC pattern insulates the Model and Controller against equi those changes. Example: : Rails applications are developed using the Model View Controller (MVC) pattern. ‘The easiest way to show how Rails uses MVC is by looking at a simplified example of the Rails request lifecycle as seen in fig.. Figure . MVC in action: the Rails request lifecycle js the uset int 1. Your grandmother fires up her web browser and hits your application with a request for some page. This request arrives at a Controller, whose job it is to determine what needs to be done in order to fulfill the request. 2. The Controller needs to fetch some data from the database, so it asks aModel, ~~" whose job it is to communicate with the database, make SQL calls to fetch records, and to know if data is valid or not, © The Model fetches data and gives it to the Controller. 3. The Controller needs the data in the form of HTML to give back to the Client (in a this case, your grandmother’s web browser), so it gives a View the data it now has. 4. The View combines the data with a temptate to gerierate a HTML page and returns thé-page to the ControHér. 5. The Controller givesthé rendered x ML page back to the Client as a response. X \ — Page ake TS, a in \ 14,— . h 4 Step 3 Create Controller. StudentController.java public class StudentController { private Student model; private StudentView view; public StudentController(Student model, StudentView view) { this.mode] = model; this. view = view; } 2 public void setStudentName(String name) { model.setName(naime); } public String getStudentName(){ return model.getName(); } public void setStudentRolINo(String rolINo){ model.setRolINo(rollNo); } public String getStudentRolfNoQ{ return model.getRollNo(); } public void updateView({ view printStudentDetails(model. getName(), model.getRolINo()); } } Step 4 Use the StudentController methods to demonstrate MVC design pattern usage. MVCPatternDemojava public class MVCPatternDemo { public static void main(String[] args) { //fetch student record based on his roll no from the database Student model = retriveStudentFromDatabase(); ‘Create a view : to write student details on console StudentView view = new StudentView(); StudentController controller = new StudentController(model, view); controller.update View(); /hapdate model data controller.setStudentName("John") 5 controller.updateView(); private static Student tetriveStudentFromDatabase(){ Page 16 SKC Lakshmi Narain College of Technology, Indore oe — N SKCLNCT cation for Execution” Student student = new Student(; student.setName("Robert"); student.setRolINo("10"); return student; } } Step 5 Verify the output. Student: Name: Robert Roll No: 10 Student: Name: Julie Roll No: 10 Conclusion: Thus we have studied MVC Architecture. Page 17 SKC Lakshmi Narain College of Technology, Indore CT . GROUP OF COLLEGES ion for Execution” + Bean provider Bean providers (also called bean developers) er z logic of the business methods within them, aa Se ne beans and write the home and remote or local interfaces for the beans and thee: the remote home or local descriptors. Bean providers don’t necessarily need to kn: y ried the beans’ deployment assembled and deployed. ow how their beans will be + Application assembler Application assemblers write the applications that us 5 applications usually include other components, such oe Goren a These Pages pages (ISP), and servlets. These components are assembled are ee cnoeenaas application. Assemblers add assembly instructions to the bean Epi eed buted Although appa assemblers must be familiar with the methods c Santhed Gel i 5. ie aie eae so they can call them, they don’tneed to know how those methods are 2. Infrastructure roles applications that use them cannot run. Although the two infrastructure roles are distinc they are almost always assumed by the same vendor. Together they provide ariel services to the enterprise beans and provide an environment in which to run. These are the two infrastructure roles: + EJB server provider EJB server providers are specialists in distributed transaction management, distributed objects, and other low-level services. They provide an application framework in which to run EJB containers. EJB service providers must provide, at a minimum, a naming service and a transaction service to the beans. + EJB container provider EJB container providers provide the deployment tools required to deploy enterprise beans and the runtime support for the beans. Acontainer provides management services to one or more beans. They communicate for the beans with the EJB server to access the services the bean needs. EJB architecture Multi-tier distributed applications often consist of a client that runs on a local machine, a middle-tier that runs on a server that contains the business logic, and a backend-tier consisting of an enterprise information system (EIS). An EIS can be a relational database system, an ERP system, a legacy application, or any data store that holds the data that needs to be accessed. This figure shows a typical EJB multi-tier distributed system with three tiers: the client, the server, the container, and the beans deployed on them; and the enterprise information system. Page SKC Lakshmi Narain College of Technology, Indore —— ee eee: rss . ORBUP OF COLLEGES jon for Execution™ | BIB Server Because our interest is how to develop enterprise beans, our focus is the middle tier. The EJB server ; 4 : f The EJB server provides system services to enterprise beans and manages the containers in which the beans run. It must make available a JNDLaccessible naming service and a transaction service. Frequently an EJB server provides additional features that distinguish it from its competitors. The Borland Enterprise Server AppServer Edition 5 0.2-5.1..xis an example of an EJB server. i ; The EJB container i ; A container is a runtime system for one or more enterprise beans. It provides the communication between the beans and the EJB server. It provides transaction, security, and network distribution management. A container is both code and a tool that generates code specific for a particular enterprise bean. A container also provides tools for the deployment of an enterprise bean, and a means for the container to monitor and manage the application. : : i The EJB server and EJB container together provide the environment for the bean to: . run in. The container provides management services to one or more beans. The server provides services to the bean, but the container interacts on behalf ofthe beansto.. .. ) - obtain those services. Almost always the EJB server and the EJB container are made by the same vendor and are simply two parts of an application server, such.as Borland Enterprise Server AppServer Edition 5.0.2 — 5.1.x. heilet i tte The bean developer must create these interfaces and classes: Page 20 SKC i Nain College of Teac Lakshmi Narain College of T echnology, I