Modularity Computer Science 3. What is Modularity? Computer systems are organized into components called modules. The extent to which this is done is.

Slides:



Advertisements
Similar presentations
Functions. COMP104 Functions / Slide 2 Introduction to Functions * A complex problem is often easier to solve by dividing it into several smaller parts,
Advertisements

Procedural programming in Java
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
ECE122 L4: Creating Objects February 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects.
Introduction to Computers and Programming Introduction to Methods in Java.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Math class methods & User defined methods Math class methods Math.sqrt(4.0) Math.random() java.lang is the library/package that provides Math class methods.
Classes we can write our own classes – to represent and define our objects e.g. class for Complex objects represents a complex number defines its properties.
Java Library Java provides a huge library or collection of useful programs A gold mine of well-tested code that can save you countless hours of development.
 2007 Pearson Education, Inc. All rights reserved C Functions.
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
 2007 Pearson Education, Inc. All rights reserved C Functions.
 2003 Prentice Hall, Inc. All rights reserved Introduction Modules –Small pieces of a problem e.g., divide and conquer –Facilitate design, implementation,
External Sorting Problem: Sorting data sets too large to fit into main memory. –Assume data are stored on disk drive. To sort, portions of the data must.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Dale Roberts Procedural Programming using Java Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Modular Programming. Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Recursion, Complexity, and Sorting By Andrew Zeng.
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Week1 Using the Library (the Java API) Classes are grouped together in packages –To use a class you have to know which package it is in –Every package.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
1 Lecture04: Function Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
1 The String Class Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks,
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
Javadoc Comments.  Java API has a documentation tool called javadoc  The javadoc tool is used on the source code embedded with javadoc-style comments.
10-Nov-15 Java Object Oriented Programming What is it?
Procedural programming in Java Methods, parameters and return values.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A class represents a single concept from the problem domain, or a.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Lesson 6 – Libraries & APIs Libraries & APIs. Objective: We will explore how to take advantage of the huge number of pre-made classes provided with Java.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
The Math Class Methods Utilizing the Important Math Operations of Java!
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
How to Test Methods Computer Science 3 Gerb Objective: Test methods properly.
Computer Graphics Basic Maths for Graphics in C++ CO2409 Computer Graphics Week 4.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Packages. The main feature of OOP is its ability to support the reuse of code: –Extending the classes –Extending interfaces The features in basic form.
Computer Science 112 Fundamentals of Programming II.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Introduction Modules Small pieces of a problem ▴ e.g., divide and conquer Facilitate design, implementation, operation and maintenance of large programs.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
1 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used as a type to declare an object reference.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Computer Graphics Basic Maths for Graphics in C++
Dept of Computer Science University of Maryland College Park
Object Oriented Systems Lecture 03 Method
Deitel- C:How to Program (5ed)
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 6 Methods: A Deeper Look
MSIS 655 Advanced Business Applications Programming
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Building a program (Java libraries) - an example
Using java libraries CGS3416 spring 2019.
Presentation transcript:

Modularity Computer Science 3

What is Modularity? Computer systems are organized into components called modules. The extent to which this is done is called modularity. To make your software more modular: –Functions with fewer inputs/outputs –Break up long functions –Break up code that is hard to understand

Why is Modularity Important? Benefits of modularity:  Individually test components  Smaller portions to understand at once  Modules can be reused For the benefits to happen, modules must:  Be small (rarely >25 lines, never >50)  Be simple (few inputs/outputs)  Have a clearly explainable function

Example: What does this do? Read in a list L of names REPEAT FOR each adjacent pair of Names in L DO Call the earlier N 1 Call the later N 2 IF N 2 is alphabetically before N 1 THEN Swap N 1 and N 2 END FOR UNTIL a pass with no swaps Write out L

How about this? Read in a list L of names Sort L alphabetically Write out L The 2nd algorithm is more modular – the sorting mechanics is moved to a module.

Testing Modules Modules are typically tested by calling them from specialized functions called drivers. –The module is tested in the form it will be used –I.e. do not add special code, otherwise the module may not work when it is removed –Don’t want to change a module after it has been tested

Summary Modular programs are divided up into smaller parts with clear interfaces –Easier to modify –Easier to understand Modules are tested with special programs called drivers Want to avoid changing a module after it is tested.

Java Standard Class Library Java provides a number of classes available for use. –These are called the Java Standard Class Library –A class library is a group of classes usable by Java programs. Details of these classes can be found at –In this case is the latest version of Java –Can find documentation for earlier (or later) versions

Packages Class libraries are divided into groups of classes called packages –Packages are named by a series of words separated by periods. –The leftmost name is the name of the class library. –E.g., java.lang.string. Java is the class library To use a package, use import –Place import ; at the top of your file. E.g.: import java.io.*; –Can also import a single class instead of the *: import java.io.BufferedReader;

java.lang Most classes that you have been using are members of the java.lang package. E.g.: –String –All types of exceptions No need to import java.lang.*. All programs automatically import java.lang.

The Math class java.lang.Math provide some useful static methods: –Math.sqrt(x) finds the square root of x. –Math.pow(x,y) finds x y. –Math.random() returns a random double between 0 & 1 –Math.max(x,y) and Math.min(x,y) –sin, cos, tan, log, abs, round –Lots more. Look them up if necessary.

The Random Class Import from java.utils.* Enables you to seed a psuedo-random number generator –Random() seeds it using date/time –Random(seed) lets you seed it (useful for testing). –Random.nextInt(n) gives you a random number between 0 and n-1.