cs2006 - data structures i chapter 2 principles of programming & software engineering
DESCRIPTION
3 Abstraction & Information Hiding Example: Cars brakes Client box Car Black box Push the brakes My interior design is using Cylinder brakes or Drum brakes Brake pedal pushed Car stopTRANSCRIPT
![Page 1: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/1.jpg)
CS2006 - Data Structures I
Chapter 2Principles of Programming
& Software Engineering
![Page 2: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/2.jpg)
2
Topics
Modular Design Concepts Abstraction OO Design
Encapsulation Inheritance Polymorphism
Top Down Design Structure Chart
![Page 3: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/3.jpg)
3
Abstraction & Information Hiding Example: Cars brakes
Clientbox
Car Black box
Push the brakes
My interior design isusing
Cylinder brakes or
Drum brakes
Brake pedal pushed
Car stop
![Page 4: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/4.jpg)
4
Abstraction Abstraction separates the purpose of a
module from its implementation. Example: Sorting
Clientbox
SortBlack box
Sort this data please,
I don’t care how you do it
I can sort data intoascending order without
you knowing how
Unsorted data
Sorted data
![Page 5: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/5.jpg)
5
Procedural Abstraction Procedural Abstraction is the process of
separating the purpose of a method from its implementation.
Once written the method can be used without any knowledge of how it is implemented - only need to know the parameters.
Example: nearly all methods in the entire Java API.
![Page 6: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/6.jpg)
6
Abstract Data Types ADT - a collection of data along with a set of
operations that can be performed on that data.
No details about how the data is stored or how the operations on the data are implemented.
An ADT is a general description of the design of a module with no details.
![Page 7: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/7.jpg)
7
Abstract Data Types Data Structure - the implementation of an
ADT in a programming language. The details of data storage and how
operations are performed are crucial parts of a data structure.
![Page 8: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/8.jpg)
8
ADT List Any List in general will allow the following
operations: Create an empty list Destroy a list Determine whether a list is empty Determine the number of items in a list Insert an item at a given position in the list What else?
![Page 9: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/9.jpg)
9
Object-Oriented Design Three elements to OOD:
Encapsulation - combining data and operations within one object.
Inheritance - objects can inherit data and/or methods from other objects.
Polymorphism - objects can determine operations at execution time.
Every object knows its "true" type regardless of type casting
![Page 10: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/10.jpg)
10
Inheritance A class can inherit the variables and methods of another
class. It can keep those it wants and replace those it doesn’t.
Example: our Person class. we want a class of students. we can’t change our Person class because
many people are using it as it stands perhaps we don’t have access to the source code
Create a new class called Student that extends the current class Person by the addition of a new variables and methods
Person
Student
parent classsuper class
child classsubclass
![Page 11: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/11.jpg)
11
FacultyStudent
Person
Class design extend the definition of Person
build a subclass for each specific type of person
![Page 12: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/12.jpg)
12
FacultyStudent
Person
Class hierarchyint getAge()
String getName()
float getGPA()
void setId(String new_id) void setSalary(float newSalary)
float getHoursWorked()
![Page 13: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/13.jpg)
13
Object-Oriented Design Produce a collection of objects that have
behaviours How to do
Identifying the objects in the problem UML Contents of Software Engineering (cosc 4506)
![Page 14: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/14.jpg)
14
Object-Oriented Design Consider the nouns and verbs in the
problem domainCreate a ATM machine which allow user to retrieve,
deposit, transfer and check balance of their accounts
ATMAccount: account
Open ()Close()
Account
Type: StringAmount: double
transfer (int )checkBalance()
retrievedeposit ()
![Page 15: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/15.jpg)
15
Top-Down Design Is a structured programming methodology Focused on algorithm design.
Goal is to break a large problem into a set of smaller problems that are more easily solved.
![Page 16: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/16.jpg)
16
Top-Down Design An attempt is made to solve a problem in
terms of small subproblems Divide and Conquer strategy
How?
![Page 17: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/17.jpg)
17
Top-Down Design (TDD)
Structure chart:Find Median
Get middle scoreSort scoresRead Scores
Read scoreFrom user
Insert scoreinto array
![Page 18: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/18.jpg)
18
Structure Charts
Can add some info into our structure chart to show how we share the data
Two type of info that get passed between our methods Data Control Information or flags
Thing like “perform such and such an operation” Or “ we have hit the end of file”
![Page 19: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/19.jpg)
19
Structure Charts
Use named arrows to show the data flow Data arrows
Flag arrows
![Page 20: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/20.jpg)
20
Structure Charts
Structure chart:Find Median
Get middle scoreSort scoresRead Scores
![Page 21: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/21.jpg)
21
Structure Charts Structure chart:
Find Median
Get middle scoreSort scoresRead Scores
Read score Insert scoreinto array MarkEnrty: contain score and ID
MarkArray: contain array of scores
![Page 22: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/22.jpg)
22
Structure Charts Structure chart:
Find Median
Get middle scoreSort scoresRead Scores
Read score Insert scoreinto array
EOFMarkEntry MarkEntry
MarkEnrty: contain score and IDMarkArray: contain array of scores
![Page 23: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/23.jpg)
23
Structure Charts Structure chart:
Find Median
Get middle scoreSort scoresRead Scores
Read score Insert scoreinto array
EOFMarkEntry MarkEntry
MarkEnrty: contain score and IDMarkArray: contain array of scores
MarkArray
![Page 24: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/24.jpg)
24
Structure Charts Structure chart:
Find Median
Get middle scoreSort scoresRead Scores
Read score Insert scoreinto array
EOFMarkEntry MarkEntry
MarkEnrty: contain score and IDMarkArray: contain array of scores
MarkArray MarkArrayMarkArray
![Page 25: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/25.jpg)
25
Structure Charts
The manner in which this structure diagram would be implemented as a program is obvious
It is now possible to create a skeletal program with all the method headers All you need is to fill in detail
![Page 26: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/26.jpg)
26
Structure Charts
Public class FindMedian {public static void main (..) {
}public static void readScore (int []MarkArray) { }public static void sortScore (int []MarkArray) {}public static int getMedian (int []MarkArray) {}
}
![Page 27: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/27.jpg)
27
Structure Charts
public class FindMedian {
public static void main (..) {int MarkArray [];
}public static void readScore (int []MarkArray) { }public static void sortScore (int []MarkArray) {}public static int getMedian (int []MarkArray) {}
}
![Page 28: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/28.jpg)
28
Structure Chartspublic class FindMedian {
public static void main (..) {int MarkArray [];readScore (MarkArray);
}public static void readScore (int []MarkArray) { }public static void sortScore (int []MarkArray) {}public static int getMedian (int []MarkArray) {}
}
![Page 29: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/29.jpg)
29
Structure Chartspublic class FindMedian {
public static void main (..) {int MarkArray [];readScore (MarkArray);sortScore (MarkArray);
}public static void readScore (int []MarkArray) { }public static void sortScore (int []MarkArray) {}public static int getMedian (int []MarkArray) {}
}
![Page 30: CS2006 - Data Structures I Chapter 2 Principles of Programming & Software Engineering](https://reader036.vdocument.in/reader036/viewer/2022062302/5a4d1b0c7f8b9ab05998b958/html5/thumbnails/30.jpg)
30
Structure Chartspublic class FindMedian {
public static void main (..) {int MarkArray [];readScore (MarkArray);sortScore (MarkArray);getMedian (MarkArray);
}public static void readScore (int []MarkArray) { }public static void sortScore (int []MarkArray) {}public static void getMedian (int []MarkArray) {}
}