Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 383 Object-Oriented Programming & Design Lecture 4 Martin van Bommel.

Similar presentations


Presentation on theme: "CSCI 383 Object-Oriented Programming & Design Lecture 4 Martin van Bommel."— Presentation transcript:

1 CSCI 383 Object-Oriented Programming & Design Lecture 4 Martin van Bommel

2 Fall 2010CSCI 383 Lecture 4 M. van Bommel 2 Coping with Complexity Is the complexity of a programming project linear in terms of the number of programmers involved? E.g., Can two programmers do in one month what one programmer can do in 2 months? Interconnectedness, the dependence of one portion of code on another portion, is responsible for this phenomena Abstraction mechanisms try to cope with this and object-oriented techniques offer yet another step forward

3 Fall 2010CSCI 383 Lecture 4 M. van Bommel 3 Abstraction What is abstraction? Abstraction is the purposeful suppression, or hiding, of some details of a process or artifact, in order to bring out more clearly other aspects, details, or structure Think of a model, give an example of a model Do we need it? Why? Yes, mainly because it helps us to deal with complexity

4 Fall 2010CSCI 383 Lecture 4 M. van Bommel 4 Information Hiding Information hiding is the purposeful omission of details in the development of an abstract representation Information hiding is what allows abstraction to control complexity

5 Fall 2010CSCI 383 Lecture 4 M. van Bommel 5 Abstraction in an Atlas Think of an atlas, and the various different levels of maps A map of the world, contains mountain ranges, large political boundaries A map of a continent, contains all political boundaries, large cities A map of a country, contains more cities, major roads A map of a large city, roads, major structures A map of a portion of a city, buildings, occupants Each level contains information appropriate to the level of abstraction

6 Fall 2010CSCI 383 Lecture 4 M. van Bommel 6 Levels of Abstraction At the highest level of abstraction we view a program as a community of interacting objects Important characteristics here are the lines of communication between the various agents

7 Fall 2010CSCI 383 Lecture 4 M. van Bommel 7 Levels of Abstraction (cont’d) The next level of abstraction is found in some (but not all) OO languages. A package, Unit or Name Space allows a programmer to surround a collection of objects (a small community in itself) with a layer, and control visibility from outside the module

8 Fall 2010CSCI 383 Lecture 4 M. van Bommel 8 Levels of Abstraction (cont’d) The next level of abstraction considers the relationship between two individual objects. Typically one is providing a service, and the other is using the service

9 Fall 2010CSCI 383 Lecture 4 M. van Bommel 9 Levels of Abstraction (cont’d) We can next examine just the person providing a service, independent of the client. We define the nature of the services that are offered, but not how those services are realized

10 Fall 2010CSCI 383 Lecture 4 M. van Bommel 10 Levels of Abstraction (cont’d) Next we look at the services provided, but from the implementation side public class LinkedList implements Stack... { public void pop () throws EmptyStackException {... }... } Concern here is with the high level approach to providing the designated service

11 Fall 2010CSCI 383 Lecture 4 M. van Bommel 11 Levels of Abstraction (cont’d) Finally, we consider the implementation of each method in isolation public class LinkedList implements Stack... {... public void pop () throws EmptyStackException { if (isEmpty()) throw new EmptyStackException(); removeFirst(); // delete first element of list }... } Every level is important, and often you move quickly back and forth between levels

12 Fall 2010CSCI 383 Lecture 4 M. van Bommel 12 Right Level of Abstraction A critical problem in early stages of development is to determine what details are appropriate at each level of abstraction, and (often more importantly) what details should be omitted One does not want to ignore or throw away important information But one does not want to manage too much information, or have the amount of information hide critical details

13 Fall 2010CSCI 383 Lecture 4 M. van Bommel 13 Right Level of Abstraction e.g. A chess board problem Can a 64 square chess board be tiled using 32 dominoes, each covering exactly two squares? YES In order to solve this problem, what details do we need to keep? What details can we ignore?

14 Fall 2010CSCI 383 Lecture 4 M. van Bommel 14 Right Level of Abstraction (e.g.) The mutilated chess board problem If two diagonally opposite squares are removed, can the remaining 62 squares be tiled by dominoes?

15 Fall 2010CSCI 383 Lecture 4 M. van Bommel 15 Forms of Abstraction Abstraction is used to help understand a complex system In a certain sense, abstraction is the imposition of structure on a system What are the techniques that we use for handling complexity? E.g., what is a computer?

16 Fall 2010CSCI 383 Lecture 4 M. van Bommel 16 IS-A and HAS-A Abstraction Two of the most important types of abstraction are the following: Division into parts – HAS-A abstraction Division into specialization – IS-A abstraction

17 Fall 2010CSCI 383 Lecture 4 M. van Bommel 17 HAS-A Abstraction Most common technique people use to help understand complex systems Takes a complex system and divides in into component parts, which can then be considered in isolation Characterized by sentences with the words “HAS-A” A car has-a engine and has-a transmission A window has-a menu bar Allows us to drop down a level of complexity when we consider the component in isolation

18 Fall 2010CSCI 383 Lecture 4 M. van Bommel 18 IS-A Abstraction Takes a complex system, and views it as an instance of a more general abstraction Characterized by sentences with the words “IS-A” A car is-a wheeled vehicle, which is-a means of transportation A bicycle is-a wheeled vehicle Allows us to categorize artifacts and info and make it applicable to many different situations Mammals are animals that have hair and nurse their young A cat is a mammal, a dog is a mammal, …

19 Fall 2010CSCI 383 Lecture 4 M. van Bommel 19 Other Abstractions – Composition While is-a and has-a are two important types of abstraction, there are others Composition is one example; a form of has-a; characterized by the following Primitive forms Rules for combining old values to create new ones The idea that new values can also be subject to further combination Examples include regular expressions, type systems, windows, other complex systems

20 Fall 2010CSCI 383 Lecture 4 M. van Bommel 20 Patterns When faced with a new problem, most people will consider successful solutions to previous problems with similar characteristics Patterns are another attempt to document and reuse abstractions


Download ppt "CSCI 383 Object-Oriented Programming & Design Lecture 4 Martin van Bommel."

Similar presentations


Ads by Google