1 / 40

CSSE 501 Object-Oriented Development

CSSE 501 Object-Oriented Development. Course Overview. Course Goals Fundamentals and principles of object-oriented development Object-oriented analysis, design and Programming. Assumptions. Familiar with preliminary programming background Data types

conway
Download Presentation

CSSE 501 Object-Oriented Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSSE 501 Object-Oriented Development

  2. Course Overview • Course Goals • Fundamentals and principles of object-oriented development • Object-oriented analysis, design and Programming

  3. Assumptions • Familiar with preliminary programming background • Data types • Program control structures: sequential. selection, repetition • Streams and files (program input and output) • Simple data structures: array • Compilation and execution of simple programs

  4. An Example (C++) // File name: HelloWorld.cpp // Purpose: A simple C++ program which prints "Hello World!" on the screen #include <iostream>// need this header file to support the C++ I/O system using namespace std; // telling the compiler to use namespace "std", // where the entire C++ library is declared. int main() { // Print out a sentence on the screen. // "<<" causes the expression on its right to // be directed to the device on its left. // "cout" is the standard output device -- the screen. cout << "Hello World!" << endl; return 0;// returns 0,which indicate the successful // termination of the "main" function }

  5. If not… • Decide which programming language you are going to use in this course, and pick up a book, start to read it and practice programming • No time and material in this course will be teaching you those preliminary programming experience

  6. Course Overview • Topics • Abstraction, Encapsulation • Interface and Implementation, Abstract Data Type • Object-Oriented Design Principles • Classes, Methods, Instances • Object Communication (Message Passing) • Inheritance, Multiple Inheritance

  7. Course Overview • Topics (Cont.) • Static and Dynamic Behavior • Polymorphism • Overriding, Overloading, Polymorphic Variable • Object Interconnection • Coupling and Cohesion • Reflection and Retrospection • Exception, Error Handling

  8. Course Overview • Course Website • http://fac-staff.seattleu.edu/daia/web/teaching/fall07/csse501/csse501.htm • Instructor • Lirong Dai, Ph.D., University of Texas at Dallas • Course Duties: • Material Reading • In-Class Exercises/Lab • Programming Assignments • Midterm • Final

  9. Today… • Chapter 1: Thinking Object-Oriented • Chapter 2: Abstraction

  10. Chapter 1: Thinking Object-Oriented • Why Object-Oriented? • Comparison with non-OO approaches • What is Object-Oriented?

  11. Programming • Programming a computer involves writing instructions that enable a computer to carry out a single task or a group of tasks • These set of instructions are called as programs or software • Programming languages: Java, C++, C#…

  12. An Example // File name: HelloWorld.cpp // Purpose: A simple C++ program which prints "Hello World!" on the screen #include <iostream>// need this header file to support the C++ I/O system using namespace std; // telling the compiler to use namespace "std", // where the entire C++ library is declared. int main() { // Print out a sentence on the screen. // "<<" causes the expression on its right to // be directed to the device on its left. // "cout" is the standard output device -- the screen. cout << "Hello World!" << endl; return 0;// returns 0,which indicate the successful // termination of the "main" function }

  13. A Survey of Programming Techniques/Paradigm • Unstructured Programming • Procedural Programming • Modular Programming • Object-Oriented Programming

  14. Unstructured Programming • All code is contained in a single continuous block (e.g., “main” program) • Has to rely on flow execution statements, such as GOTO (e.g., Spaghetti code) • Still used in • MS-DOS batch files • Old languages, such as BASIC, FORTRAN • Assembly language Program Main Program data

  15. MS-DOS Batch File Example rem display and check if there is an argument if "%1"=="" goto noparameter echo the parameter is %1 goto exit :noparameter echo you must supply an argument to this batch file :exit

  16. Unstructured Programming (Cont.) • Problems • Difficult to read and debug • Only works for very simple and small problems • Tremendous disadvantages once the program gets sufficiently large • For example, if the same statement sequence is needed at different locations within the program, the sequence must be copied • Solution: extractthese sequences, namethem and offer a technique to call and return from these procedures

  17. Procedural Programming • Able to combine returning sequences of statements into one single place • A procedure call is used to invoke the procedure • Data from main program to procedures (i.e., parameters) • After the sequence is processed, flow of control proceeds right after the position where the call was made • Processed data back to main program • Procedures, also known as routines, subroutines, methods, or functions Main Program Procedure Procedure calls

  18. C Program Example int add( int, int); /* Function declaration */ main() { int i=1; printf("i starts out life as %d.", i); i = add(1, 1); /* Procure/Function call */ printf(" And becomes %d after function is executed.\n", i); } /********************************************************/ int add( int a, int b) /* Procure/Function definition */ { int c; c = a + b; return c; }

  19. Procedural Programming (Cont.) • Languages • COBOL, FORTRAN, BASIC, C, Pascal … • Problems • Difficulties of reasoning about programs • To some degree difficulty of parallelization • Relatively low level • In large, complicated programs, modularity is generally desirable

  20. Modular Programming • Module • Generally, a component of a larger system, and operates within that system independently from the operations of the other components • Modular Programming • A common functionality are grouped together into separate modules • A program is now divided into several smaller parts which interact through procedure calls Main Program data Module1 data +data1 Module2 data +data2 Procedure1 Procedure2 Procedure3

  21. Modular Programming (Cont.) • Example: a singly linked list • Operations on the list • Append element in the end • Delete element at the front • Application: queue • Implement the list in two separate modules • Interface definition • Describe what is available • Implementation files • Describe how it is made available • Fundamental principles in software engineering • Change the implementation won’t affect the interface

  22. Singly List Interface Definition /* * Interface definition for a module which implements * a singly linked list for storing data of any type. */ MODULE Singly-Linked-List-1 BOOL list_initialize(); /* Initialize variables local to the module BOOL list_append(ANY data); BOOL list_delete(); list_end(); ANY list_getFirst(); ANY list_getNext(); BOOL list_isEmpty(); END Singly-Linked-List-1

  23. Singly List (Cont.) • What if we need more than one list in the program? /* * A list module for more than one list. */ MODULE Singly-Linked-List-2 DECLARE TYPE list_handle_t; /* list_handle_t represents list handle, which is used in every provided procedure to uniquely identify the list in question */ list_handle_t list_create(); list_destroy(list_handle_t this); BOOL list_append(list_handle_t this, ANY data); ANY list_getFirst(list_handle_t this); ANY list_getNext(list_handle_t this); BOOL list_isEmpty(list_handle_t this); END Singly-Linked-List-2;

  24. Singly List (Cont.) PROCEDURE foo() BEGIN list_handle_t myList; myList <- list_create(); /* Do something with myList */ ... list_destroy(myList); END PROCEDURE foo() BEGIN list_handle_t myList; /* List is created and initialized */ /* Do something with the myList */ ... END /* myList is destroyed */

  25. Singly List (Cont.) PROCEDURE foo() BEGIN SomeDataType data1; SomeOtherType data2; list_handle_t myList; myList <- list_create(); list_append(myList, data1); list_append(myList, data2); list_destroy(myList); END /* Oops */ ...

  26. Modular Programming • Problems • Decouple data and behaviors • Module is oriented on operations but not actual data • Cannot guarantee type safety • Programs can access memory in inappropriate ways • Inflexible • Hard to extend

  27. Object-Oriented Programming (OOP) • What is object-oriented programming? • Principles of object-oriented programming

  28. Kay's Description of OOP • Object-oriented programming is based on the principle of recursive design • Everything is an object • Objects perform computation by making requests of each other through the passing of messages • Every object has it's own memory, which consists of other objects • Every object is an instance of a class. A class groups similar objects • The class is the repository for behavior associated with an object • Classes are organized into singly-rooted tree structure, called an inheritance hierarchy

  29. What is an Object? • The most fundamental concept/mechanism of OOP • From an application modeling perspective, an object has the components: characteristics/attributes, services/behaviors), unique identifier, rules and policies, relationships • From a design modeling perspective, an object can be an example (instance) of a category (class), can be a category or a type, created (instantiated) by a category, can communicate…

  30. What is a Class? • From a modeling perspective, a class is a template for a category. It defines characteristics, services, rules and policies, relationships • From a design perspective, a class is a special kind of object • From an implementation perspective, a class is a “global” object with class data members and class services • From a compiler’s perspective, a class is a programmer’s defined data type

  31. Principles of Object-Orientation • Principle 1.Encapsulation: The object contains both the data and the methods (code) that manipulate or change that data

  32. Case Study In this example, we have a family with a father (John), a mother (Jane), two sons (Peter and Paul), and two daughters (Elizabeth and Mary). John is an actor and Jane is a dentist. All the children are students and the family dog is Lassie. Their family physician is Alice. This family owns a house in the suburbs. Although mowing the family lawn is normally a chore for the father, it can be a paid chore for any one of the children. However, working within the neighborhood is Jack, a professional lawn mower. One morning, Jane notices that the lawn needs mowing, so she mentions to John that it is time to mow the lawn. John agrees and says that he will mow the lawn this evening. Later that evening, John comes home and is exhausted from a long day at the studio and decides to pay one of his children to mow the lawn. He looks for one of his children; he sees Mary first. He asks Mary to mow the lawn for five dollars. Mary agrees; however, Mary knows that Jack, a professional lawn mower, is willing to mow the lawn for four dollars. So Mary calls Jack to mow the lawn for four dollars and Jack agrees to mow the lawn. Jane comes home later that evening and she sees the lawn mowed. Thinking that John mowed the lawn, Jane complements John on the excellent condition of the lawn.

  33. Principles of Object-Orientation • Principle 2.Information Hiding: The object that contains the attributes (data) defines what services (functions) are available to the other objects and prevents other objects from access or knowledge of the attributes (data) and how a service (function) is provided • Information hiding is important because it allows an object complete control over the integrity of the data contained within it. This gives us high cohesion and low coupling concerning the manipulation of data • Note: Encapsulation alone does not prevent the data of an object from being manipulated by functions other than the methods bound to the object. Protecting data from manipulation by entities outside the object can be achieved by requiring that access of data can only be provided by the services of the object that contains the data.

  34. Principles of Object-Orientation • Principle 3.Message Passing: An object may communicate with another object only via the message-passing mechanism • Each message must be sent to a designated receiver, and the interpretation of the message depends on the receiver

  35. Principles of Object-Orientation • Principle 4.Late Binding: Support for the ability to determine the specific receiver and its corresponding method (code) to be executed for a message at runtime • This is another way in which message passing in the OOP differs from a function call is that the specific receiver of any given message is not usually known until runtime, so the determination of which method to invoke cannot be made until then • Late binding enables to model a real behavior of the world. For example, if you are reading the textbook in a class at school, it is unlikely that you could have known who your classmates would be before the first day of the class. You only know who your classmates are once the class has begun, and even then some individuals might register late

  36. Principles of Object-Orientation • Principle 5.Delegation: Work is passed, via message passing, from one object (client) to another object (agent) because from the client’s perspective, the agent has the service that the client needs. Work is continuously passed until it reaches the object that has both the data and the method (code) to perform the work

  37. Principles of Object-Orientation • Principle 6.Class/Instance/Object: All objects are instances of a class. Instance can be created (instantiated) or destroyed (deleted) at runtime. How the object provides a service is determined by the class of which the object is an instance

  38. Principles of Object-Orientation • Principle 7.Generalization/Specialization: Classes can be organized by using a hierarchical inheritance structure. In the structure, the specialized class (subclass) inherits the attributes, the relationships, the methods from the generalized class (superclass) that is higher in the structure

  39. Principles of Object-Orientation • Principle 8.Relationships: Collaboration between objects to provide a service to a client are usually captured by an association relationship

  40. Principles of Object-Orientation • Principle 9.Reflection: Each object knows the detailed information about the class(es) and the interface(s) to which it is an instance. This means that an application can, at runtime, acquire information about the object from the object itself

More Related