1 / 16

18: Program design

18: Program design. Introduction. When constructing a software solution a number of elements are addressed (These will become more sophisticated as knowledge and experience grows) The user interface (Form1) The program design Class definition / construction / importation

esma
Download Presentation

18: Program design

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. 18: Program design

  2. Introduction When constructing a software solution a number of elements are addressed (These will become more sophisticated as knowledge and experience grows) The user interface (Form1) The program design • Class definition / construction / importation • Module definition / construction / importation • Interface methods (Form1 code) Testing • Identify inputs • Identify outputs Construct test cases and form test plan

  3. Example Consider the game of noughts and crosses played by two people (not against the computer ….yet!) The required program is to provide a platform to play the game by recording the ‘goes’, identifying a winner and keeping score. Accordingly we may envisage something similar to the game played with pencil and paper: Score: Peter John

  4. Form design Requires some knowledge of the implementation (programming language) to be aware of the facilities available. First thoughts! Questions? Score Player 1 Player 2 Crosses Noughts Are players to be identified? Do players take turns to be noughts and then crosses? Who starts? 3 4 Start Game over – Crosses win Draw Finish

  5. Form design – cont’d Label controls and, if significant, indicate names: Labels PictureBox: picbox Score Player 1 Player 2 Crosses Noughts Textboxes:txtPlayer1Score txtPlayer2Score Label:lblResult 3 4 RadioButtons: rdbPlayer2 rdbPlayer1 Start Label (Flashing) Button:cmdFinish Play Abandon Finish Button: cmdPlay Button: cmdAbandon

  6. Analysis Suppose : The players are identified as Player 1 and Player 2, and Player 1 is identify before the program is run. Player 1 - Crosses start Play will alternate during a game and on the start of subsequent games A game can be abandoned by clicking the ‘Abandon’ button Picture design: Use 50 pixel black and white squareslocated by top left vertex

  7. Class design Identify any class definitions to be imported: • Square Identify any classes to be constructed and specify their members • a (chequered) Boarddisplay areashow: to make the board visible • a Game – to record goes and check for winner display areaentries: an integer array to store goes, -1 for nought and 1 for crossturns: to store number of turns takengetEntry: to retrieve a give entry valueshowSymbol: to draw symbol gameOver: to check for winner and indicate winning line or indicate draw

  8. Class definitions • Board

  9. Class definitions – cont’d • Game

  10. Class definitions – cont’d Game – cont’d

  11. Form1 methods Brainstorm what operations need to carried out and order them: • Initialisation • Set initial values of global (?) variables, E.g. scores • Set up interface • Start game • Initialise variables specific to a particular game, E.g. record of goes, number of turns • Display board • Flash prompt • Manage a ‘go’

  12. Form1 methods – cont’d Decide how methods will be invoked: click-handler, call from within some other method? • Initialisation - MyBase.Load • Start game - cmdPlay • Flash prompt - Timer1.Tick • Manage a ‘go’ - picBox.MouseDown • Check for a win - Game method/function • Identify winner - Game method/function In this way the problem is broken down into smaller subtasks. Tackle each of these subtasks; if necessary, develop their solution in separate projects. Assemble the whole and adjust to work. This might mean going back and modifying some of the constituent components. Run

  13. Review code Revisit the code to • Eliminate redundancy • Make more readable/intelligible by restructuring, breaking large methods into smaller parts, consider introducing functions • Check the need for global variables and where possible make local • Introduce comments if not already present. Perform tests to identify problems, deficiencies, etc.Each time you complete a set of changes, re-run all test cases.

  14. Looking for deficiencies Manage a ‘go’

  15. Example - deficiency What happens if a player selects an occupied cell? What will happen if player continues after game has been won? - Need to identify and prohibit these situations. Accordingly, we have

  16. Deficiency – cont’d and: Run

More Related