Programming Layer Lecture 8 Layers of Computing Systems





































- Slides: 37

Programming Layer Lecture 8

Layers of Computing Systems Communications Applications Operating Systems Programming Hardware Information

Programming Layer Top down design Object oriented design Programming Procedural programming Low level programming OOP High level programming

Problem Solving • The act of finding a solution to a perplexing question • A computer is not intelligent – Computer can do nothing without being told what to do. – cannot analyze a problem and come up with a solution. – Human (the programmer) must analyze the problem, develop the instructions for solving the problem (the program), and then have the computer carry out the instructions.

HOW TO SOLVE IT by G. Polya 1. You have to understand the problem. 2. Find the connection between the data and the unknown. – You may be obliged to consider auxiliary problems if an immediate connection cannot be found. – You should obtain eventually a plan of the solution (algorithm). 3. Carry out your plan – test the solution to see if it works 4. Examine the solution obtained – for future re-use

Problem solving strategies heuristics • Look for Familiar Things – never reinvent the wheel. If a solution exists, use it. If you’ve solved the same or a similar problem before, just repeat the successful solution. • Divide and Conquer – break up a large problem into smaller pieces that we can solve individually.

Algorithm • Algorithm – unambiguous instructions for solving a problem or subproblem in a finite amount of time using a finite amount of data

Pseudocode – presenting algorithm • Pseudocode - uses a mixture of English and formatting to make the steps in the solution explicit. Used to present the algorithm

The computer problem-solving process

The interaction between problem-solving phases

PROBLEM SOLVING METHODOLOGIES

Problem solving methodologies • top-down design (also called functional decomposition) – A technique for developing a program in which the problem is divided into more easily handled subproblems, the solutions of which create a solution to the overall problem • object-oriented design (OOD). – Data and the algorithms that manipulate the data are bundled together in the object-oriented view, thus making each object responsible for its own manipulation (behavior). – Underlying object-oriented design (OOD) are the concepts of classes and objects.

Problem solving methodologies TOP-DOWN DESIGN

Top-down design • Create hierarchical structure, also known as a tree structure, of problems and subproblems, called modules. – Module - a self-contained collection of steps that solves a problem or subproblem • Modules at one level can call on the services of modules at a lower level. – These modules are the basic building blocks of an algorithm.

An example of top-down design

Worked example: Subdividing the party planning

Example: computer example • Problem: Create an address list that includes each person’s name, address, telephone number, and e-mail address. – This list should then be printed in alphabetical order. – The names to be included in the list are on scraps of paper and business cards.



Summary of top-down methodology 1. 2. 3. 4. Analyze the Problem Write the Main Module Write the Remaining Modules Re-Sequence and Revise as Necessary

Problem solving methodologies OBJECT-ORIENTED DESIGN (OOD)

Object-oriented design • Object-oriented design is a problem-solving methodology that produces a solution to a problem in terms of self-contained entities called objects, which are composed of both data and operations that manipulate the data. – Object-oriented design focuses on the objects and their interactions within a problem.

Object Orientation • Object - An entity or thing that is relevant in the context of a problem • Object class or class - A description of a group of objects with similar properties and behaviors • Fields - Named items in a class; can be data or subprograms • Method - A named algorithm that defines one aspect of the behavior of a class

Relationships between Classes • Containment - A mechanism whereby one class contains an object of another class as a field • Inheritance - A mechanism by which one class acquires the properties - data fields and methods - of another class

Object-Oriented Design Methodology • Brainstorming and Filtering – Determining the possible classes in the problem and filter the ones that can be combined or identify missing ones – Record the resulting set in CRC cards CRC - Class-responsibility-collaboration card • Scenarios – is the stage in which the behavior of each class is determined. – assign responsibilities to each class - the tasks that each class must perform. Responsibilities are eventually implemented as subprograms. • what a class must know about itself (knowledge) and what a class must be able to do (behavior). • A class encapsulates its data (knowledge) - objects in one class cannot directly access data in another class. • Responsibility Algorithms – algorithms must be written for the responsibilities. – Because of the process of focusing on data rather than actions in the object oriented view of design, the algorithms for carrying out responsibilities tend to be fairly short. • Knowledge responsibilities usually just return the contents of one of an object’s variables, or send a message to another object to retrieve it. • Action responsibilities are a little more complicated, often involving calculations

Example: problem definition • Problem: Create an address list that includes each person’s name, address, telephone number, and e-mail address. This list should then be printed in alphabetical order. The names to be included in the list are on scraps of paper and business cards.

Example: Brainstorming and Filtering • What are the possible objects? – There must be the host or hostess, the guests, the menu, and the food. • Where is the party going to be? – We need an address object. • Are the invitations to be done by phone or by invitation? – Let’s assume by written invitation, so we have invitation objects.

Example: Brainstorming and Filtering

Example: Brainstorming and Filtering Initial list Filtered list address list name address phone number email list order names list paper Craps cards address list name address telephone email

Record data to CRC cards


Responsibility algorithms • Person class - There are two responsibilities to be decomposed: initialize and print. – Because each of the fields of the class is a class, we can just let each initialize and print itself.

Responsibility algorithms • Name class This class has the same two responsibilities: initialize and print; however, the algorithms are different. – For Initialize, the user must be prompted to enter the name and the algorithm must read the name. – For Print, the first and last names must be output with appropriate labels.

Responsibility algorithms • Address, Telephone, and E-mail classes – The algorithms for the responsibilities for these classes are mirror images of the algorithms for class Name.

Important topics in OOD • Information hiding The practice of hiding the details of a module with the goal of controlling access to the details of the module • Abstraction A model of a complex system that includes only the details essential to the viewer – Data abstraction - The separation of the logical view of data from its implementation – Procedural abstraction - The separation of the logical view of an action from its implementation – Control abstraction - The separation of the logical view of a control structure from its implementation – Control structure - A statement used to alter the normally sequential flow of control

Programming languages • Programming language - A set of rules, symbols, and special words used to construct a program that is, to express a sequence of instructions for a computer • Program - A sequence of instructions written to perform a specified task • Syntax - The formal rules governing the construction of valid instructions • Semantics - The set of rules that gives the meaning of instructions in a language

Homework • Computer Science Illuminated, Chapter 6, end of the book exercises