Introduction to Classes and OO Programming. - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Introduction to Classes and OO Programming.

Description:

One major problem with the work covered so far is that we have created programs ... of the company are often drifting into a soporific state and falling asleep. ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 21
Provided by: matt131
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Classes and OO Programming.


1
Introduction to Classes and OO Programming.
2
  • One major problem with the work covered so far is
    that we have created programs based solely on a
    single form.
  • When programming real systems in VB.NET your
    project is seldom limited to a single form.
  • Many programs have a number of forms (components)
    and these forms need to be managed in a sensible
    way.

3
Hire Car System.
  • May involve the following forms
  • Password Screen.
  • Main Menu.
  • Customer Details Form.
  • Booking Form.

4
Issues to Consider with Multiple Forms.
  • 1. Problems with code duplication.
  • We dont want sections of code repeated.
  • 2. Problems with code re-use.
  • We want to be able to recycle our code.

5
Consider A Search Facility.
  • Imagine you had a form in your system which
    allows you to search for cars, e.g. those that
    are free for hire on a specific date, those that
    are of a certain make etc. This form is used to
    make bookings for customers.

6
Search Facility Version 1
  • Search button on a form.
  • Code exists within a Sub Procedure within the
    form.

7
Search Facility Version 2
  • Search for cars that are in need of
    servicing/various states of damage.

8
Code Duplication.
  • The first problem we have created here is
    potential for code duplication.
  • By having a search facility in both forms we have
    two sections of search code which are going to be
    pretty similar.

9
A Solution?
  • One solution might be to only place the search
    code behind one of the forms and then somehow
    call the search from one form to another.
  • Q. Is this an acceptable solution?
  • We have solved the problem of duplication but are
    now faced with a few other problems.
  • Firstly to call the code in one form from another
    we need to have both forms open, when all that we
    want is the facility to search.

10
Q. So how do we solve this problem?
  • A. We introduce the idea of a Class Module.

11
Features of a Class.
  • Two main features of a class are methods and
    properties.
  • Methods (Sometimes referred to as Operations.)
    e.g. DoSearch.
  • Properties (Sometimes referred to as Attributes)
    e.g. Count.

12
Methods and Properties You have Used Already!
  • Methods.
  • lstStudents.Items.Add
  • lstStudents.Items.RemoveAt
  • MessageBox.Show("Hello World")
  • Properties.
  • txtInput.Text
  • btnDelete.Enabled

13
The Reminder Application.
  • For the next four weeks we shall be building a
    small but useable multi form application called
    Reminders.
  • The program allows the user to set timed
    reminders (alarms) which will "go off" at
    specified points in time.
  • In a moment we shall look at the finished program.

14
The Universal Modelling Language Documentation.
  • In addition to the program you have been provided
    with a set of documentation using the Universal
    Modelling Language, (UML).
  • UML is a set of documents that may be used to
    plan design and document object oriented (OO)
    programs like the Reminder application.
  • Some of you have seen UML documentation in your
    Systems Analysis and Design Module.

15
Instantiation Classes v Objects.
  • When you create a class, you are creating a
    template from which you make your objects.
  • For example in Word you have a set of templates
    for such things as letters and memos. When you
    create a new letter, you take a copy of the
    template and make an actual instance of a letter.

16
Encapsulation Public v Private.
  • One important feature of using classes is that we
    really don't care how they work.
  • For example to add an item to a list box we might
    use the following line of code
  • lstMyList.Items.Add("Hello")
  • The Add method is all we are interested in, we
    don't care how it adds the word "Hello" to the
    list just that it will do it.

17
Project Description GNiteall plc
  • GNiteall is a company specialising in the
    manufacture of aromatic oils to assist with
    insomnia. Unfortunately due to the effectiveness
    of their products and continued exposure, the
    employees of the company are often drifting into
    a soporific state and falling asleep.
  • The management wish to address this problem by
    ensuring that each employee has installed on
    their computer a reminder system which will alert
    staff of important appointments (which they are
    often missing).
  • The initial stages of the project will allow the
    user to add, edit and delete timed reminders that
    will activate at the appropriate time and alert
    the user. A later revision of the program will
    add sound thus waking the user, but at this stage
    a basic implementation is proposed.

18
Use Case Diagram.
19
Use Case Description.
  • Reminder Management
  • The user adds a new reminder to the reminder
    list.
  • The user edits an existing reminder in the
    reminder list.
  • The user deletes a reminder in the reminder list.
  • The user opens a reminder list.
  • The user closes a reminder list.
  • The user snoozes a reminder by 10 minutes.
  • The timer triggers an active reminder.

20
Class Diagram.
Write a Comment
User Comments (0)
About PowerShow.com