introduction to computer science for engineers
play

Introduction to Computer Science for Engineers L-3: Object-Oriented - PowerPoint PPT Presentation

I C S E Introduction to Computer Science for Engineers L-3: Object-Oriented Design ICSE Exercise Update Working during the weekend is not very comfortable :/ Hence, we change the rhythm of publishing/submitting exercises tasks


  1. I C S E Introduction to Computer Science for Engineers L-3: Object-Oriented Design

  2. ICSE Exercise Update • Working during the weekend is not very comfortable :/ • Hence, we change the rhythm of publishing/submitting exercises • tasks will be published approx. 10 days before the exercise 
 —> on monday evening or tuesday morning • submission deadline will be fridays (before the corresponding exercise) at 2 pm! ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 2

  3. Some Old Slides

  4. ICSE a comment Source Code: Welcome /* A simple Java Program,which says Welcome to ICSE */ the class name (Save code as Welcome.java) public class Welcome { a variable public static int var ; a method public static void say (String s) { System.out.print(“Welcome to”+s); } public static void main (String[] argv) { say(”ICSE!"); } The main method (The entry point while executing the program) } ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 4

  5. ICSE a comment Source Code: Welcome /* A simple Java Program,which says Welcome to ICSE */ the class name (Save code as Welcome.java) public class Welcome { a variable public static int var ; public static void main (String[] argv) { a method public static void say (String s) { System.out.print(“Welcome to”+s); } public static void main (String[] argv) { say(”ICSE!"); } The main method (The entry point while executing the program) } ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 5

  6. ICSE Methods Signature: name combined with the number and types of its parameters • Example: Call of the method for max for int and double parameter • Notes: d2 : implicit type conversion int à double • i2 : explicit type conversion double à int • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 6

  7. ICSE Methods double i1 = max (1,2); Signature: int i2 = max ( (int) d2, i1); name combined with the number and types of its parameters • … Example: Call of the method for max for int and double parameter • Notes: d2 : implicit type conversion int à double • i2 : explicit type conversion double à int • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 7

  8. ICSE Content Object-Oriented Design Goals, Principles and Pattern • Inheritance • Overloading vs. Overriding • Types of Inheritance • Interfaces and Abstract Classes • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 8

  9. Object-Oriented Design: 
 Goals, Principles and Design Patterns

  10. ICSE Object-Oriented Design: Goals ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 10

  11. ICSE Object-Oriented Design: Goals Robustness: to be capable of handling unexpected inputs that are not • explicitly defined for its application ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 11

  12. ICSE Object-Oriented Design: Goals Robustness: to be capable of handling unexpected inputs that are not • explicitly defined for its application Adaptability: to be able to evolve over time in response to changing • conditions in its environment ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 12

  13. ICSE Object-Oriented Design: Goals Robustness: to be capable of handling unexpected inputs that are not • explicitly defined for its application Adaptability: to be able to evolve over time in response to changing • conditions in its environment Portability (related concept): • the ability of software to run with minimal change on 
 • different hardware and operation system platforms ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 13

  14. ICSE Object-Oriented Design: Goals Robustness: to be capable of handling unexpected inputs that are not explicitly • defined for its application Adaptability: to be able to evolve over time in response to changing conditions in • its environment Portability (related concept): • the ability of software to run with minimal change on 
 • different hardware and operation system platforms Reusability: to be able to use the same code in a component of different systems • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 14

  15. ICSE Object-Oriented Design: Principles ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 15

  16. ICSE Object-Oriented Design: Principles Abstraction: to distill a system down to its most fundamental parts • to describe the parts of a system involves naming them and • explaining their functionality to hide the implementation details from the user • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 16

  17. ICSE Object-Oriented Design: Principles Abstraction: to distill a system down to its most fundamental parts • to describe the parts of a system involves naming them and explaining • their functionality to hide the implementation details from the user • Example: Abstract Data Types (ADT) • a mathematical model of a data structure that specifies the type of data • stored, the operations supported on them, and the types of parameters of the operations expressed by an interface: • specifies what each operation does, but not how it does it • realized by a class: • specifies how the operations are performed a • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 17

  18. ICSE Object-Oriented Design: Principles Encapsulation: to hide the implementation details of different components of • a software system each module maintains a consistent interface but reveals • no internal details for outsiders gives the programmers the freedom in implementing the • details ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 18

  19. ICSE Object-Oriented Design: Principles Encapsulation: to hide the implementation details of different components of a • software system each module maintains a consistent interface but reveals no • internal details for outsiders gives the programmers the freedom in implementing the details • Modularity: refers to an organizing principle in which different components • of a software system are divided into separate independent functional units to reduce complexity ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 19

  20. ICSE Object-Oriented Design: Design Patterns Design patterns: provides a general template for a solution that can be applied in many • different situations. Elements of a design pattern: Name: • to identify the pattern; • Context: • describes the scenarios for which this pattern can be applied • Template: • describes how to implement the pattern • Result: • describes and analyzes what the pattern produces • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 20

  21. Classes and Objects: Basic Concepts

  22. ICSE Classes and Objects Class: a template/blue print, defining the data which the object stores and the methods for accessing and modifying that data Classes can contain any of the following variable types: local variables: data inside methods, constructors or blocks. • will be declared and initialized within the method • will be destroyed when the method has completed • instance variables: data within a class but outside any method • will be initialized when the class is instantiated • can be accessed from inside any method, constructor or blocks • Methods represent operations that can act on the data associated consists of constructors, procedures, and functions • ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 22

  23. ICSE Classes and Objects Class: a template/blue print, defining the data which the object stores and the methods for accessing and modifying that data variables: represent the data associated with an object • methods: operations that can act on the data associated • public class Counter { public int count; // instance variable public Counter( ) { } // method (default constructor) public Counter(int a){ // method (constructor with one parameter) int count = a; // local variable } public void increment( ){count++;} // change the instance variable public void increment(int a){count+=a;} // change the instance variable public int getCount( ) {return count;} // an accessor method } } ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 23

  24. ICSE Classes and Objects Keyword this to differentiate between an instance variable and a local variable • with the same name allow one constructor body to invoke another constructor body • public class Counter { public int count; // instance variable public Counter( ) { // method (default constructor) this(0); // invoke one-parameter constructor with value zero } super(values); public Counter(int a){ // method (constructor with one-parameter) this.count = a; // set the instance variable equal to parameter } } ICSE: Introduction to Computer Sciences for Engineers – L-3 (WS16/17) 24

Recommend


More recommend