logging in or signing up 30 Misree Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 37 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (0) Added: December 07, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Designing Multi-class ProgramsCOMP 102 #30 2 Oct 2007: Designing Multi-class Programs COMP 102 #30 2 Oct 2007Outline: Outline Multi-Class programs Class Diagrams Designing MiniDraw Implementing Interface classes. Reading: L&L Chapter 8 Interfaces. Announcements: Lab 10 availableDesigning Programs: Designing Programs What happens when programs get large? More classes More interactions Harder to understand.Designing Programs: Designing Programs The central problem in programming is handling complexity The central techniques to handle complexity are: Modularity: Breaking problems into smaller parts that can be solved separately. ⇒ methods: a separate method for each subtask ⇒ classes: a separate class for each component of the program Questions: how big is a module? Abstraction: Hiding the details of a module, so that other parts of the program only need to know a little bit about it: eg: name, parameters, return type constructor and possible actions Questions: what should you show? what should you hide?Designing Classes: Designing Classes Interesting programs require multiple classes Design problem: How do you break a task into classes?Choosing Classes !!!!!!!!!: No fixed Formula! It is a matter of good design, but… Separate the user interface from the rest of the program. One class to set up the interface and handle the interaction (typically only one object of this class is created) Other classes to store and manipulate the information (typically multiple objects of these classes are created) Have a separate class for each type of information One class for the Flower; another for the collection of flowers. One class for a Cell; another for the Grid of Cells. One class for the Maze; another class for the Mouse; another class for cells of the Maze; another class for coordinates; another class for Directions. L&L 6.2 talks about an approach for identifying potential classes for a problem. Choosing Classes !!!!!!!!!Designing Classes: Designing Classes Grid (Assig 9) (The user interface and controller) (The collection of Squares) (Individual Squares)Class Diagrams: Class Diagrams Class diagrams can help in understanding a program : Box for each class Arrows to show that one class uses another class Has variables of the type of the other class private Flower[ ] flowers; Calls methods or constructors from the other class flowers = new Flower(20, 10); flowers[i].bloom(); Refers to public static fields of the other class min = Integer.MAX_VALUE; (field of Integer class) eg, in Grid.java: cells[r][c].draw(canvas,x, y, MineSweeper.cellSize, MineSweeper.cellSize) Other arrows for other relationships.Class Diagrams: Class Diagrams Class boxes may list the class “interface”: [ L&L: 4.1 ] public constructors, methods, and possibly fields ⇒ the elements of the class that other classes can access also need a description of the semantics of the class (only given by comments in most languages) Java ⇒ javadoc documentation The “interface” of a class is the abstraction represented by the class other classes do not need to know any other details BlueJ automatically draws class diagrams for you It sometimes misses out some arrows doesn’t display the “interface” easily. Makes it easy to see the javadoc documentation of a class (if you wrote javadoc comments: /** ….. */) “Interface” is ambiguous:: “Interface” is ambiguous: “Interface” is the boundary/connection between two things User interface: boundary between computer and user Class interface: boundary between class and rest of program A Java Interface: Special kind of class that only defines a typejavadoc describes the “interface”: javadoc describes the “interface” Use the javadoc description of a class when writing code that uses that class: Designing MiniDraw (Assig 10): Designing MiniDraw (Assig 10) A simple drawing editor Allows user to create drawings consisting of shapes: rectangles, ovals, lines, text strings, dots, trees, different colours. can add a new shape, remove a shape move a shape to a different position save the current drawing to a file load a previous drawing from a file and edit it further. Run the demo! You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
30 Misree Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 37 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (0) Added: December 07, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Designing Multi-class ProgramsCOMP 102 #30 2 Oct 2007: Designing Multi-class Programs COMP 102 #30 2 Oct 2007Outline: Outline Multi-Class programs Class Diagrams Designing MiniDraw Implementing Interface classes. Reading: L&L Chapter 8 Interfaces. Announcements: Lab 10 availableDesigning Programs: Designing Programs What happens when programs get large? More classes More interactions Harder to understand.Designing Programs: Designing Programs The central problem in programming is handling complexity The central techniques to handle complexity are: Modularity: Breaking problems into smaller parts that can be solved separately. ⇒ methods: a separate method for each subtask ⇒ classes: a separate class for each component of the program Questions: how big is a module? Abstraction: Hiding the details of a module, so that other parts of the program only need to know a little bit about it: eg: name, parameters, return type constructor and possible actions Questions: what should you show? what should you hide?Designing Classes: Designing Classes Interesting programs require multiple classes Design problem: How do you break a task into classes?Choosing Classes !!!!!!!!!: No fixed Formula! It is a matter of good design, but… Separate the user interface from the rest of the program. One class to set up the interface and handle the interaction (typically only one object of this class is created) Other classes to store and manipulate the information (typically multiple objects of these classes are created) Have a separate class for each type of information One class for the Flower; another for the collection of flowers. One class for a Cell; another for the Grid of Cells. One class for the Maze; another class for the Mouse; another class for cells of the Maze; another class for coordinates; another class for Directions. L&L 6.2 talks about an approach for identifying potential classes for a problem. Choosing Classes !!!!!!!!!Designing Classes: Designing Classes Grid (Assig 9) (The user interface and controller) (The collection of Squares) (Individual Squares)Class Diagrams: Class Diagrams Class diagrams can help in understanding a program : Box for each class Arrows to show that one class uses another class Has variables of the type of the other class private Flower[ ] flowers; Calls methods or constructors from the other class flowers = new Flower(20, 10); flowers[i].bloom(); Refers to public static fields of the other class min = Integer.MAX_VALUE; (field of Integer class) eg, in Grid.java: cells[r][c].draw(canvas,x, y, MineSweeper.cellSize, MineSweeper.cellSize) Other arrows for other relationships.Class Diagrams: Class Diagrams Class boxes may list the class “interface”: [ L&L: 4.1 ] public constructors, methods, and possibly fields ⇒ the elements of the class that other classes can access also need a description of the semantics of the class (only given by comments in most languages) Java ⇒ javadoc documentation The “interface” of a class is the abstraction represented by the class other classes do not need to know any other details BlueJ automatically draws class diagrams for you It sometimes misses out some arrows doesn’t display the “interface” easily. Makes it easy to see the javadoc documentation of a class (if you wrote javadoc comments: /** ….. */) “Interface” is ambiguous:: “Interface” is ambiguous: “Interface” is the boundary/connection between two things User interface: boundary between computer and user Class interface: boundary between class and rest of program A Java Interface: Special kind of class that only defines a typejavadoc describes the “interface”: javadoc describes the “interface” Use the javadoc description of a class when writing code that uses that class: Designing MiniDraw (Assig 10): Designing MiniDraw (Assig 10) A simple drawing editor Allows user to create drawings consisting of shapes: rectangles, ovals, lines, text strings, dots, trees, different colours. can add a new shape, remove a shape move a shape to a different position save the current drawing to a file load a previous drawing from a file and edit it further. Run the demo!