Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 11: Object Oriented Programming

Class 11: Object Oriented Programming

Notes for 7/25/2013

Ian Luke Kane

July 25, 2013
Tweet

More Decks by Ian Luke Kane

Other Decks in Technology

Transcript

  1. Procedural  Programming  Review Design  Method  =  Top  Down Start  with

     a  problem  (procedure)  and  then   systema<cally  break  the  problem  down  into  sub   problems  (sub  procedures).   Procedures,  also  known  as  rou<nes,  subrou<nes,   methods,  or  func<ons  simply  contain  a  series  of   computa<onal  steps  to  be  carried  out. Issues?
  2. SegSim  Explana6on “Segrega<on  Simula<on”:  A  simple  model  for  inves<ga<ng  how

      over  <me  communi<es  can  become  segregated  based  on   various  prejudices.   1. Break  the  problem  down  into  one  dimension;  a  street   ini<ally  populated  with  equal  probability  either  black  ‘B’,   white  ‘W’  or  empty  ‘  ‘  houses.   2. We  then  allow  the  system  to  evolve  by  randomly  selec<ng   houses  and  applying  a  simple  condi<on:  If  the  house  is   surrounded  on  both  sides  by  a  house  different  to  itself,  it   will  decide  to  move  to  an  empty  loca<on  in  the  street  where   this  condi<on  is  not  sa<sfied.  In  the  unlikely  event  that  a   suitable  loca<on  cannot  be  found  aRer  a  designated   number  of  aSempts,  the  house  will  leave  the  street.
  3. SegSim  Sample  Output | BW W BWB BWBBWWBWWW W B

    BW BW WW BWW BWWW | : 17 | BW W BWB BWBBWWBWWW WBB BW BW WW WW BWWW | : 15 | BW W BWB BWBBWWBWWW WBB B BWWWW WW BWWW | : 13 | BBW W BWB BWBBWWBWWW WBB B WWWW WW BWWW | : 11 | BBW W BWBBBWBBWWBWWW WBB B WWWW WW WWW | : 8 | BBW BWBBBWBBWWBWWWWWBB B WWWW WW WWW | : 6 | BBW BWBBB BBWWBWWWWWBB B WWWW WW WWWW | : 5 | BBW WBBB BBWWBWWWWWBB BB WWWW WW WWWW | : 3 | BBWW BBB BBWWBWWWWWBB BB WWWW WW WWWW | : 1 | BBWW BBBB BBWW WWWWWBB BB WWWW WW WWWW | : 0
  4. SegSim  Modified  Rules Suppose  we  want  to  add  a  different

     type  of  house  that   plays  by  different  rules,  then  see  how  the  simula:on   differs?   Consider  a  nomad  type  house  (label  ‘N’)    which  does  not   care  about  its  neighbors.  However,  it  remembers  how  long   it  has  been  in  one  loca:on,  and  if  longer  than  a  specified   threshold  it  moves  to  a  new  loca:on. How  must  we  modify  the  original  (procedural)  program  in   order  to  account  for  these  new  rules?
  5. Object  Oriented  Programming An  object  oriented  program  may  be  viewed

     as  a   collec<on  of  interac<ng  objects,  as  opposed  to  the   procedural  model,  in  which  a  program  is  seen  as  a  list   of  func+ons  to  perform. The  aim  of  object-­‐oriented  programming  is  to  try  to   increase  the  flexibility  and  maintainability  of   programs. Data  before  ac+on.
  6. Object  Oriented  Programming A  programming  paradigm  that  represents  concepts  

    as  objects  that  have  data  fields  (proper+es  that   describe  the  object)  and  associated  procedures   known  as  methods. Objects,  which  are  instances  of  classes,  are  used  to   interact  with  one  another  to  design  applica<ons  and   computer  programs. Some  verbiage  can  vary.
  7. What  is  a  class? A  collec<on  of  objects  that  have

     common  proper+es,   opera<ons  and  behaviors.     A  combina<on  of  state  (proper+es)  and  behavior   (methods).         A  data  type,  and  objects  are  instances  of  that  data   type.  In  other  words,  classes  are  prototypes  from   which  objects  are  created.   The  blueprint.
  8. What  is  an  object? An  instance  of  a  class.  

      An  object  receives  all  of  the  characteris<cs  of  a  class,   including  all  of  its  default  data  and  any  ac<ons  that   can  be  performed  by  its  methods. Objects  can  communicate.   An  object  passes  a  message  to  another  object,  which   results  in  the  invoca<on  of  a  method.     The  “object”  you  build  from  the  blueprint.
  9. What  is  a  method? A  set  of  func<ons  contained  within

     a  class. Allows  you  to  do  “stuff.” The  response  to  a  message  is  execu<ng  a  method. Sending  a  message  means  calling  a  method.
  10. What  is  a  property? A  default  set  of  data  stored

     in  a  class.   A  class  can  have  mul<ple  proper<es  and  the   proper<es  can  be  changed  dynamically  through  the   methods  of  the  class.
  11. What  is  inheritance? Mul<ple  classes  may  share  some  of  the

     same   characteris<cs,  and  have  things  in  common  with  one   another,  but  also  may  have  certain  proper<es  that   make  them  different.     Object  oriented  programming  allows  classes  to   inherit  commonly  used  state  and  behavior  from   other  classes.  
  12. Major  Dis6nc6on Procedural   • Uses  procedures  to  operate  on

     data  structures* Object-­‐Oriented   • Bundles  the  two  together,  so  an  object,  which  is  an   instance  of  a  class,  operates  on  its  "own"  data   structure. *  A  par'cular  way  of  storing  and  organizing  data  in  a   computer  so  that  it  can  be  used  efficiently