Principles of Programming. Achieving an Object-Oriented Design  Abstraction and Information Hiding  Object-Oriented Design  Functional Decomposition.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

Introducing JavaScript
P5, M1, D1.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
Software Engineering and Design Principles Chapter 1.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
COS Sept 9, 2005 Key Issues in Programming Stefan Brandle.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Fall 2007CS 2251 Software Engineering Intro. Fall 2007CS 2252 Topics Software challenge Life-cycle models Design Issues Documentation Abstraction.
Chapter 1 Principles of Programming and Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ASP.NET Programming with C# and SQL Server First Edition
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
® IBM Software Group © 2006 IBM Corporation Writing Good Use Cases Module 4: Detailing a Use Case.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
An Object-Oriented Approach to Programming Logic and Design
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
CSE 219 Computer Science III Program Design Principles.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
SE: CHAPTER 7 Writing The Program
1 Life Cycle of Software Specification Design –Risk Analysis –Verification Coding Testing –Refining –Production Maintenance.
Software Development. Software Developers Refresher A person or organization that designs software and writes the programs. Software development is the.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
A Use Case Primer 1. The Benefits of Use Cases  Compared to traditional methods, use cases are easy to write and to read.  Use cases force the developers.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
The Software Development Process
Code Conventions Tonga Institute of Higher Education.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Learners Support Publications Object Oriented Programming.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Program Style Chapter 22 IB103 Week 12 (part 2). Modularity: the ability to reuse code Encapsulation: hide data access directly but may use methods (the.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Chapter 2 Principles of Programming and Software Engineering.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Principles of Programming & Software Engineering
Principles of Programming and Software Engineering
About the Presentations
Figure 1.1 The life cycle of software as a water wheel that can rotate from one phase to any of phase.
Figure 1.1 The life cycle of software as a water wheel that can rotate from one phase to any of phase.
PROGRAMMING METHODOLOGY
Anatomy of a Java Program
Presentation transcript:

Principles of Programming

Achieving an Object-Oriented Design  Abstraction and Information Hiding  Object-Oriented Design  Functional Decomposition  Using UML to Model Designs  Advantages of an Object-Oriented Approach

Abstraction and Information Hiding  Procedural Abstraction  Data Abstraction  Information Hiding

Procedural Abstraction  Separates the purpose of a method from its implementation.  Specifies what a method assumes and what it does, but not how it does it.  You can change how a method works without having to change the methods that use it.  Allows you to use code written by others without having to study the code.

Data Abstraction  A collection of data and a set of operations on the data (abstract data type).  You can use the operations, if you know their specifications, without knowing how they are implemented or how the data is stored.

Information Hiding  The hiding of implementation details, especially relating to how data is stored, from external access.  As a user of a module, you do not need to worry about the details of implementation, and as an implementer of a module, you do not need to worry about its uses.

Object-Oriented Design  Classes, Objects, and Instances  Encapsulation  Inheritance  Polymorphism

Objects, Classes, and Instances  The objects in a problem environment are the things that get used, created, and/or manipulated.  A class is a template for a collection of objects that are similar or of the same type.  An instance is a specific member of a class.

Encapsulation  It is the combining of data and operations on that data.  It is a mechanism that helps with information hiding because it hides the inner details of the implementation from external modules.

Inheritance  The properties of a class can be inherited from another class.  This allows you to reuse classes defined earlier for different purposes with appropriate modification.  In the new class some of the methods can be modified and new ones can be added.

Polymorphism  This is a mechanism that enables determination to be made at execution time as to which method is the right one to use based on the type of objects operated on.  For example, the + operator between two numbers means addition, but between two strings it means concatenation.

Functional Decomposition  The successive refinement of function into more specific functional elements.  It is the breaking down of a complex task into more manageable single-purpose tasks and subtasks.  This is also referred to as top down design.

Using UML to Model Designs Class Diagram Example: Clock -hour: integer = 12 -minute: integer = 0 -second: integer = 0 +setTime(in hr: integer, in min: integer, in sec: integer) -advanceTime() +displayTime() {query}

Advantages of an Object- Oriented Approach  Although extra time and effort is required when using object-oriented programming (OOP), it is usually worth it.  After you identify the classes needed for your problem and how they interact with each other, you can focus on one class at a time which simplifies implementation.  Once you have implemented a class, it is much easier to implement similar classes since you can inherit properties. (reuse)  You can make a change to an ancestor class and affect all descendant classes.

Key Issues in Programming  Modularity  Modifiability  Ease of Use  Fail-safe Programming  Style  Debugging

Modularity  Modularity has a favorable impact on: Constructing the program Debugging the program Reading the program Modifying the program Eliminating redundant code

Constructing the Program  Because the modules are independent writing one large modular program is not much different from writing many small, independent programs.  Modularity permits team programming where several programmers work independently on their own modules before combining them into one program.

Debugging the Program  The task of debugging a large program is reduced to the task of debugging many small programs.  If you thoroughly test modules as you go along, you can be almost sure that newly found bugs are in the newest module introduced.  Modular programs are more amenable to formal methods of verification.

Reading the Program  Just as modularity helps the programmer to deal with the complexity of the problem, it also helps the reader to do the same.  A modular program is easy to follow because the reader can get a good idea of what is going on without reading any code.  A well-written can be understood fairly well just from its name.

Modifying the Program  A small change in requirements will likely require modification of only one or a small number of modules.  With modularity you can reduce a large modification into a set of small and relatively simple modifications.

Eliminating Redundant Code  You can identify a computation that occurs in many places in your program and implement it as a method.  This improves both readability and modiyfiability.

Modifyiability  The use of methods, e.g., creating a sort method rather than embedding the code in the main body of the program, makes a program easier to modify.  Using named constants, e.g., for the number of students in the class, can make a program that processes information about members of the class easier to modify if that number changes.

Ease of Use  In an interactive environment, the program should always prompt the user for input in a manner that makes it clear what is expected.  A program should always echo its input.  The output should be well labeled and easy to read.

Fail-Safe Programming  A fail-safe program is one that will perform reasonably well no matter how anyone uses it.  You need to try to anticipate how people might misuse the program and guard against these abuses.  There are two main types of errors to guard against: Errors in input data Errors in logic

Style  Five issues of style 1. Extensive use of methods 2. Use of private data fields 3. Error handling 4. Readability 5. Documentation

Extensive Use of Methods  If a set of statements performs an identifiable, recurring task, it should be a method.  The use of methods is cost effective even if it adversely affects performance because of the human effort saved.

Use of Private Data Fields  You should hide the exact representation of data fields of an object by making them private.  This supports the principle of information hiding.  Use accessor and mutator methods to access and change the data values of an object.

Error Handling  In most cases a method should return a value or throw and exception instead of displaying an error message when a problem is encountered.

Readability  For a program to be easy to follow, it should have: A good structure and design A good choice of identifiers Good indentation and use of white space Good documentation

Identifier Conventions User-defined identifiers are both upper- and lowercase letters as follows: Class names are nouns, with each word in the identifier capitalized. Method names are verbs, with the first letter lowercase and subsequent internal words capitalized. Variable names begin with a lowercase letter and subsequent internal words capitalized. Named constants are entirely uppercase and underscores are used to separate words.

Indentation Style  Use blank lines to offset each method.  Indent individual blocks of code visibly and offset them with blank lines.  Indentation should be consistent.  Try to avoid rightward drift.

Indentation Style  With regard to braces ({, }) there are two acceptable styles. 1. Put the opening brace at the end of the line that begins the compound statement and the closing brace should be on a line by itself, lined up with the with the beginning of the line that begins the compound statement. 2. Put the opening brace on a line by itself immediately following and lined up with the beginning of the line that begins the compound statement. The closing brace is as above.  Braces should be used around all statements, even single statements, when they are part of a control structure.

Documentation  A program should be well documented (commented) so that others can read, use, and modify it easily.  You should comment your code as you go along, not just as a last step.  You may be the one who benefits most from your own documentation.

Essential Features of Program Documentation 1. An initial comment for the program that includes: a. Author and date b. Description of the program’s input and output c. Description of how to use the program d. Assumptions such as the type of data expected e. Statement of purpose f. Statement of exceptions, that is, what could go wrong g. Brief description of the major classes

Essential Features of Program Documentation (Cont’d) 2. Initial comments in each class that state its purpose and describe the data contained in the class (constants and variables). 3. Initial comments in each method that state its purpose, preconditions, postconditions, and methods called. 4. Comments in the body of each method to explain important features or subtle logic.

Debugging  Programs that are modular, clear and well documented are generally easier to debug.  Fail-safe techniques are also a great aid to debugging.  Use System.out.println statements as necessary.

Debugging (Cont’d)  Debugging methods: You should examine the values of a method’s arguments at its beginning and end.  Debugging loops: You should examine the values of key variables at the beginnings and ends of loops,  Debugging if statements: Just before the if statement you should examine the values of the variables within its expression.  Remember to either comment out or remove debugging code inserted.