1 / 10

CTEC2902 Advanced Programming

CTEC2902 Advanced Programming. Designing Your Own Classes. Designing Your Own Classes. The story so far… You know how to Use ready-made classes in your code Write class code So, you can now start designing your own Let us carry on… . Designing Any Class - Four Steps.

ratana
Download Presentation

CTEC2902 Advanced Programming

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. CTEC2902Advanced Programming Designing Your Own Classes Designing Classes

  2. Designing Your Own Classes • The story so far… • You know how to • Use ready-made classes in your code • Write class code • So, you can now start designing your own • Let us carry on… Designing Classes

  3. Designing Any Class - Four Steps Service (orFunctionality Requirement) Document A summary of the service to be provided by the class. (0 or more properties & methods - How long is a piece of string?) Namespace: Class name: Inherits: Designing Classes

  4. Designing Your Own Classes • Property or Method? • If simple access to data is required, • with simple validation/formatting, use property • If complex processing is required, use method • Use the Functionality Requirement Document • Nouns indicate properties • Verbs indicate methods Sometimes, either will do. Go with personal preference Designing Classes

  5. Designing BankAccount Class Service Manages different types of bank accounts and keeps track of the current balance. The account can be “Black”, “Orange”, or “Red”, depending on the balance. Positive balance earns interest. Namespace: nsBankOps Class name: clsAccount Inherits: none Designing Classes

  6. Designing AcademicModule Class Service Manages an academic module. Each module is managed by its leader; is 15 or 30 credits; and is run at a specific level of study. Assessment is by coursework and examination. Namespace: nsDMU Class name: clsModule Inherits: None Designing Classes

  7. Designing Encyclopaedia Class Service Manages an encyclopaedia. The user submits a word and its explanation is returned. The user may add new words or remove existing words. Namespace: nsEnglish Class name: clsEncyclopedia Inherits: None Designing Classes

  8. Exercise Design a class to represent a student Namespace: nsDMU Class name: clsStudent Inherits: None Exercise Design a class to represent a city Namespace: nsUK Class name: clsCity Inherits: None Designing Classes

  9. Designing Your Own Classes • Summary • Your design must end with the class API, specifying • Service provided by the class • Properties – name, type, data limits, etc. • Methods – name, type, parameters, functionality • Constructors – parameters, functionality Designing Classes

  10. Designing Your Own Classes • Warning and Advice • Designing a class is difficult • Implementing a class is easy • So, spend time on the design; • try out “what if” scenarios Designing Classes

More Related