Hannah Whaley - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Hannah Whaley

Description:

... of real world' objects in programming ... visible or accessible to outside world/other classes ... will be set on a clock displayed in minutes and hours ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 18
Provided by: hannah87
Category:
Tags: clock | hannah | whaley | world

less

Transcript and Presenter's Notes

Title: Hannah Whaley


1
Intro to OOP
  • UK Developers Workshop 2006
  • Hannah Whaley

2
What well cover
  • What is OOP?
  • Benefits of OOP
  • OOP and BB
  • Examples
  • Main Principles
  • Designing for OOP

3
What is Object Oriented Programming?
  • Paradigm for programming, replacing procedural as
    industry standard
  • Bridges the gap between concepts that humans know
    and concepts computers know
  • Uses the idea of real world objects in
    programming
  • OOP lets you model a collection of objects that
    communicate to achieve a complex task

4
Benefits of OOP
  • Code is broken into small pieces
  • Reusable
  • Easily maintainable
  • Only change something in one place
  • Can find it and read it easier
  • Reduces complex structures into simple ones
  • More natural, readable structure
  • It scales well
  • Lots of libraries use other peoples pieces
  • Collectively these small pieces become complex

5
Classes and objects
  • Class
  • Description of a group of items with
  • common properties (variables)
  • common behaviours (methods)
  • Like a blueprint
  • Object
  • Instance of a class
  • what it knows (variables)
  • what it can do (methods)

6
Example
  • Cat class
  • Colour, breed, age, number of paws, tail
  • Instance of a cat (specific state)
  • Black, Bombay, 13 weeks
  • Another instance of a cat (different state)
  • Ginger, Tabby, 3 years

All have access to behaviours such as meowing,
scratching, hunting, eating etc.
7
Blackboard and OOP
  • Blackboard is written in an object oriented style
  • We can declare instances of classes that they
    have created and use them in our code
  • Can get and set variables, and call the methods
    contained in the class

8
Blackboard Example
  • Blackboard have created the User Class
  • We can declare an instance of a User
  • Can access get and set methods
  • Can set the variables to be the current users
    details
  • Can get the variables and print them to screen

User localUser ctx.getUser()
String localFirstname localUser.getGivenName()
out.println(Hi localFirstname) Hi Hannah
9
More Concepts of OOP
  • Encapsulation
  • Ensure all related code and data are kept
    together
  • Not directly visible or accessible to outside
    world/other classes
  • Access to data and code has to be explicitly
    allowed
  • Like its in a capsule o)

10
More Concepts of OOP
  • Inheritance
  • Can derive new classes from existing ones
  • Can extend existing program code
  • Form class hierarchies
  • Class Animal
  • Class Cat
  • Class Dog
  • Both extend Animal Class, but will define
    additional states and behaviours
  • A good example in Blackboard is the
    authentication, where it is not uncommon to write
    a Custom Authentication module that extends
    Blackboards original one

11
More Concepts of OOP
  • Polymorphism
  • A variable declared to be of a certain class can
    refer to objects of that class or any subclass
  • A more abstract level of design
  • Could design an algorithm to fill a list with
    objects and print each of their details
  • List could contain different objects, so long as
    they all had a print method

12
Coupling and Cohesion
  • Coupling
  • How closely two classes depend on each other
  • The more dependant, the more tightly coupled they
    are
  • Low coupling is best!
  • Cohesion
  • The number and type of responsibilities a class
    has
  • The more varied the responsibilities, the lower
    the cohesion
  • High cohesion is best!

13
Designing for OOP
  • If you are writing your own classes you want to
    design them well
  • Remember encapsulation
  • Remember coupling and cohesion
  • There are ways to decide on what will become
    classes and what fields and methods they should
    have
  • Take a requirements document and highlight all
    the nouns
  • These make a list of candidate classes
  • Accept or reject them
  • Irrelevant
  • Repeated
  • Variable
  • Write descriptions for the accepted classes
  • Look for verbs for methods

14
Candidate Class Example
  • Requirements for alarm system
  • We plan to use an alarm system to end
    presentations on time
  • The end time will be set on a clock displayed in
    minutes and hours
  • The system will check the clock time and ring a
    bell when the clock gets to that time

15
Candidate Class Example
  • Requirements for alarm system
  • We plan to use an alarm system to end
    presentations on time
  • The end time will be set on a clock displayed in
    minutes and hours
  • The system will check the clock time and ring a
    bell when the clock gets to that time
  • Possible classes
  • Alarm Accept
  • System Reject, irrelevant
  • Time Reject, attribute of clock
  • Clock Accept
  • Minutes Reject, attribute of clock
  • Hours Reject, attribute of clock
  • System Reject, repeated
  • Bell Reject, attribute of Alarm
  • Clock Reject, repeated
  • Time Reject, repeated

16
Candidate Class Example
  • Alarm
  • Bell
  • RingBell()
  • Clock
  • Hours
  • Minutes
  • Time
  • SetTime()
  • GetTime()

Times UP!!!!!!!!
17
The End
  • That has hopefully been either a quick intro or a
    quick refresher to OOP
  • Well see code examples for BB that demonstrate
    this through the day
  • Any questions?
Write a Comment
User Comments (0)
About PowerShow.com