International Journal of Computer Network and Security (IJCNS) Vol. 3 No. 1 ISSN : 0975-8283
Software Design Pattern Using : Algorithmic Skeleton Approach S. Sarika Lecturer,Department of Computer Sciene and Engineering Sathyabama University, Chennai-119. [email protected]
Abstract - In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Many patterns imply object-orientation or more generally mutable state, and so may not be as applicable in functional programming languages, in which data is immutable Fig 1. Primary design pattern or treated as such..Not all software patterns are design patterns. For instance, algorithms solve 1.1Attributes related to design : computational problems rather than software design Expandability : The degree to which the design of a problems.In this paper we try to focous the system can be extended. algorithimic pattern for good software design. Simplicity : The degree to which the design of a Key words - Software Design, Design Patterns, system can be understood easily. Software esuability,Alogrithmic pattern. Reusability : The degree to which a piece of design can be reused in another design. 1. INTRODUCTION Many studies in the literature (including some by 1.2 Attributes related to implementation: these authors) have for premise that design patterns Learn ability : The degree to which the code source of improve the quality of object-oriented software systems, a system is easy to learn. because design patterns are supposed to improve the Understandability : The degree to which the code quality of systems[1], for example, a tangled source can be understood easily. implementation of patterns impacts negatively quality Also, patterns generally ease future enhancement at the Modularity : The degree to which the implementation expense of simplicity. There is little empirical evidence of the functions of a system are independent from one to support the claims of improved reusability, another. expandability and understandability as put forward in 1.3 Attributes related to runtime : when applying design patterns. We present detailed Generality: The degree to which a system provides a results for three design pat-terns: Abstract Factory, wide range of functions at runtime. Composite, Flyweight and three quality attributes: reusability, understandability, and expandability. Modularity at runtime: The degree to which the functions of a system are independent from one another The following set of quality attributes, based on at runtime. their relevance to design patterns[2]. 2. ALGORITHMIC SKELETON In computing, algorithmic skeletons (a.k.a. Parallelism Patterns) are a high-level parallel programming model for parallel [3] [4] and distributed computing. Algorithmic skeletons take advantage of common programming patterns to hide the complexity of parallel and distributed applications. Starting from a basic set of patterns (skeletons), more complex patterns
72 International Journal of Computer Network and Security (IJCNS) Vol. 3 No. 1 ISSN : 0975-8283 can be built by combining the basic ones.This section public Seq(Execute
describes some well known Algorithmic Skeleton execute){...} patterns. Additionally, the patterns signature in the 3. EXAMPLE PROGRAM Skandium library is provided for clarity. The following example is based on the Java FARM is also known as master-slave. Farm represents Skandium library for parallel programming.The task replication where the execution of different tasks objective is to implement an Algorithmic Skeleton by the same farm are replicated and executed in based parallel version of the QuickSort algorithm parallel. using the Divide and Conquer pattern. Notice that the Farm(Skeleton
keleton){...} high-level approach hides Thread management from the programmer. PIPE represents staged computation. Different tasks can be computed simultaneously on different pipe // 1. Define the skeleton program stages. A pipe can have a variable number of stages, Skeleton stage1, new SplitList(), Skeleton stage2){...} new Sort(), FOR represents fixed iteration, where a task is new MergeList()); executed a fixed number of times. In some // 2. Input parameters implementations the executions may take place in parallel.[5] Future skeleton, int times){...} // 3. Do something else here. WHILE represents conditional iteration, where a given skeleton is executed until a condition is met. // ... public While(Skeleton skeleton, // 4. Block for the results Condition condition){...} Range result = future.get(); IF represents conditional branching, where the The first thing is to define a new instance of the execution choice between two skeleton patterns is skeleton with the functional code that fills the pattern decided by a condition. (ShouldSplit, SplitList, Sort, MergeList). The If(Condition condition, functional code is written by the programmer without Skeleton trueCase, Skeleton parallelism concerns. falseCase){...} The second step is the input of data which triggers MAP represents split, execute, merge computation. A the computation. In this case Range is a class holding task is divided into sub-tasks, sub-tasks are executed in an array and two indexes which allow the parallel according to a given skeleton, and finally sub- representation of a subarray. For every data entered into task's results are merged to produce the original task's the framework a new Future object is created. More result[6]. than one Future can be entered into a skeleton split, simultaneously. Skeleton condition, Condition split, Skeleton skeleton, Merge 73 International Journal of Computer Network and Security (IJCNS) Vol. 3 No. 1 ISSN : 0975-8283 this.maxTimes = maxTimes; storage, reducing not just processing time but also allocation & deallocation of working memory. this.times = 0; 4.4.PRECOMPUTATION } Precomputing a complete range of results prior to @Override compiling, or at the beginning of an algorithm's public synchronized boolean execution[11], can often increase algorithmic efficiency condition(Range r){ substantially. This becomes advantageous when one or more inputs is constrained to a small enough range that return r.right - r.left > the results can be stored in a reasonably sized block of threshold && memory. times++ < this.maxTimes; 5. SOFTWARE VALIDATION VERSUS } HARDWARE VALIDATION An optimization technique that was frequently } taken advantage of on legacy platforms was that of 4. ALGORITHMIC EFFICIENCY allowing the hardware (or microcode) to perform In computer science, efficiency is used to describe validation on numeric data fields[12]. The choice was properties of an algorithm relating to how much of to either spend processing time checking each field for various types of resources it consumes[7][8]. a valid numeric content in the particular internal Algorithmic efficiency can be thought of as analogous representation chosen or simply assume the data was to engineering productivity for a repeating or correct and let the hardware detect the error upon continuous process. execution. The choice was highly significant because to check for validity on multiple fields (for sometimes 4.1 SOFTWARE METRICS many millions of input records), it could occupy The two most frequently encountered and valuable computer resources. Since input data fields measurable metrics of an algorithm are:-speed or were in any case frequently built from the output of running time - the time it takes for an algorithm to earlier computers[13] complete, and 'space' - the memory or 'non-volatile 6. CONCULSION storage' used by the algorithm during its operation. Different software development models will focus Transmission size - such as required bandwidth the desing effort at different points in the development during normal operation or size of Eternal memory- process. Newer development models, such as such as temporary disk space used to accomplish its algorithamic skeleton often employ desing case task. development and place an increased portion of the 4.2 SPEED desing in the hands of the developer, before it reaches a formal team of designers. In this paper we foucs that The absolute speed of an algorithm for a given the Algorithmic skeletons take advantage of common input can simply be measured as the duration of programming patterns to hide the complexity of parallel execution (or clock time) and the results can be and distributed applications. averaged over several executions to eliminate possible random effects[9]. Most modern processors operate in 7. REFERENCES a multi-processing & multi-programming environment [1] Beck, Kent; Ward Cunningham (September 2009). so consideration must be made for parallel processes "Using Pattern Languages for Object-Oriented Program". occurring on the same physical machine, eliminating OOPSLA '87 workshop on Specification and Design for these as far as possible. Object-Oriented Programming. OOPSLA '09. [2] Baroni, Aline Lúcia; Yann-Gaël Guéhéneuc and Hervé 4.3 MEMORY Albin-Amiot (June 2003). "Design Patterns It is possible to make an algorithm faster at the Formalization" (PDF). Nantes: École Nationale expense of memory. This might be the case whenever Supérieure des Techniques Industrielles et des Mines de the result of an 'expensive' calculation is cached rather Nantes.] than recalculating it afresh each time[10]. The [3] Erl, Thomas (2009). SOA Design Patterns. New York: additional memory requirement would, in this case, be Prentice Hall/PearsonPTR. pp. 864. ISBN 0-13-613516-1. considered additional overhead although, in many [4] http://soa.sys-con.com/node/809800 situations, the stored result occupies very little extra [5] Meyer, Bertrand; Karine Arnout (July 2006). space and can often be held in pre-compiled static "Componentization: The Visitor Example". IEEE Computer (IEEE) 39 74 International Journal of Computer Network and Security (IJCNS) Vol. 3 No. 1 ISSN : 0975-8283 [6] Laakso, Sari A. (2003-09-16). "Collection of User Interface Design Patterns". University of Helsinki, Dept. of Computer Science. http://www.cs.helsinki.fi/u/salaakso/patterns/index.html. Retrieved 2008-01-31. [7] Heer, J.; M. Agrawala (2006). "Software Design Patterns for Information Visualization". IEEE Transactions on Visualization and Computer Graphics 12 (5): 853. doi:10.1109/TVCG.2006.178.. [8] Chad Dougherty et al (2009). Secure Design Patterns. http://www.cert.org/archive/pdf/09tr010.pdf. [9] Simson L. Garfinkel (2005). Design Principles and Patterns for Computer Systems That Are Simultaneously Secure andUsable.. [10] "Yahoo! Design Pattern Library". http://developer.yahoo.com/ypatterns/. Retrieved 2008- 01-31. [11] "How to design your Business Model as a Lean Startup?". http://torgronsund.wordpress.com/2010/01/06/lean- startup-business-model-pattern/. Retrieved 2010-01-06. [12] Pattern Languages of Programming, Conference proceedings (annual, 2009) [1] [13] McConnell, Steve (June 2004). "Design in Construction". Code Complete (2nd ed.). Microsoft Press. pp. 104. ISBN 978-0735619678. "Table 5.1 Popular Design Patterns" 75