background preloader

Introduction to Systematic Program Design - Part 1

Introduction to Systematic Program Design - Part 1
About the Course Phones, diesel engines, animated newspapers, medical devices, games, political campaigns, medical research, mining, transportation systems, ... and so on, and on, and on... every day more of the world around us is at least partly run by computer programs. This means that being able to design programs - or at least be able to work with people who design programs - is becoming a more and more valuable skill. To build your own programs you need to know two things: how to use the specific programming language and libraries needed, and the more general skill of how to design a program. This course presents a design method that will enable you to approach the design of complex programs systematically. The method will work for programs in this course as well as hard to design programs you develop in the future. In the first course -- Part 1 -- we use a simple teaching language to cover the core of the design method. Course Syllabus Week Two: Representing information as data.

Design Patterns Strategy Pattern In Strategy pattern, a class behavior or its algorithm can be changed at run time. This type of design pattern comes under behavior pattern. In Strategy pattern, we create objects which represent various strategies and a context object whose behavior varies as per its strategy object. Implementation We are going to create a Strategy interface defining an action and concrete strategy classes implementing the Strategy interface. StrategyPatternDemo, our demo class, will use Context and strategy objects to demonstrate change in Context behaviour based on strategy it deploys or uses. Step 1 Create an interface. Strategy.java public interface Strategy { public int doOperation(int num1, int num2);} Step 2 Create concrete classes implementing the same interface. OperationAdd.java public class OperationAdd implements Strategy{ @Override public int doOperation(int num1, int num2) { return num1 + num2; }} OperationSubstract.java OperationMultiply.java Step 3 Create Context Class. Context.java Step 4 Step 5

Related: