• Save
OO programming   introduction
Upcoming SlideShare
Loading in...5
×
 

OO programming introduction

on

  • 1,254 views

An introduction to OO Programming. ...

An introduction to OO Programming.
Visit http://jpereira.eu/2012/04/11/oo-design-principles-or-guidelines-part-1/ for more information. If you want to download the presentation, contact me (find my contacts on my page)

Statistics

Views

Total Views
1,254
Views on SlideShare
727
Embed Views
527

Actions

Likes
3
Downloads
1
Comments
0

6 Embeds 527

http://jpereira.eu 510
http://investing.jpereira.eu 9
http://www.linkedin.com 5
http://cache.baidu.com 1
http://feeds2.feedburner.com 1
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

OO programming   introduction OO programming introduction Presentation Transcript

  • OO Programming - Introduction João Pereira October 2012 OO Programming - Introduction by João Miguel Pereira is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming- Introduction Refreshing OO programming conceptsOO Programming - Introduction is licensed under a Creative Commons Attribution- 2NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming Concepts Why do I need objects ?OO Programming - Introduction is licensed under a Creative Commons Attribution- 3NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming Concepts • I can easily model real world concepts. CarOO Programming - Introduction is licensed under a Creative Commons Attribution- 4NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming Concepts • I can focus on the data and behavior of the atoms of my system Focus on grouping the Wheel state for a Diameter wheel Weight Model supporting Load Move() autoCalibrate() checkPressure() Focus on currentLoad() grouping the behaviorOO Programming - Introduction is licensed under a Creative Commons Attribution- 5NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming Concepts • I can share objects and still have everything I need to use them in other systems Machine A Machine B Object Object Object’s Object’s state Network state Object’s Object’s behavior behaviorOO Programming - Introduction is licensed under a Creative Commons Attribution- 6NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming Concepts • I can build small, manageable, self- contained objects and use them as building blocks for bigger things Wheel Wheel Wheel Seat Belt Wheel Wheel Tire Objects Car OO ProgramOO Programming - Introduction is licensed under a Creative Commons Attribution- 7NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming Concepts • I can reuse objects to build different systems Wheel Wheel Wheel Seat Seat Objects Bike OO ProgramOO Programming - Introduction is licensed under a Creative Commons Attribution- 8NonCommercial-ShareAlike 3.0 Unported License.
  • OO Programming Concepts More?OO Programming - Introduction is licensed under a Creative Commons Attribution- 9NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO How I design and code?OO Programming - Introduction is licensed under a Creative Commons Attribution- 10NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO • I don’t try to build the perfect solution • Tend to be creative • Brainstorm, sometimes with myself • Implement alternatives • Refactor my code • Get a bird-eye view on the whole system, frequently • Focus my effort on small parts of the system (a Class at a time)OO Programming - Introduction is licensed under a Creative Commons Attribution- 11NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possible • And…. – Know the design principles – Reuse knowledge (Patterns)OO Programming - Introduction is licensed under a Creative Commons Attribution- 12NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possibleOO Programming - Introduction is licensed under a Creative Commons Attribution- 13NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Interface and Implementation interface Services that my objects expose to my object’s clients public class Computer { private PowerSupply powerSupply; public void turnOn() { turnOnPowerSupply(); } public void turnOff() { turnOffPowerSupply(); } private void turnOffPowerSupply() { powerSupply.turnOff(); } private void turnOnPowerSupply() { powerSupply.turnOn(); } }OO Programming - Introduction is licensed under a Creative Commons Attribution- 14NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Interface and Implementation implementation Implementation is how the object realize the services expected by the clients public class Computer { private PowerSupply powerSupply; public void turnOn() { turnOnPowerSupply(); } public void turnOff() { turnOffPowerSupply(); } private void turnOffPowerSupply() { powerSupply.turnOff(); } private void turnOnPowerSupply() { powerSupply.turnOn(); } }OO Programming - Introduction is licensed under a Creative Commons Attribution- 15NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Interface and Implementation • Object’s clients can be other objectsOO Programming - Introduction is licensed under a Creative Commons Attribution- 16NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Interface and Implementation • If an implementation change, clients don’t care, as long as the interface provides them the service they expect public class Computer { public void turnOn() { PowerSupply.on(); } public void turnOff() { PowerSupply.off(); }}OO Programming - Introduction is licensed under a Creative Commons Attribution- 17NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possibleOO Programming - Introduction is licensed under a Creative Commons Attribution- 18NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Think Abstractly • Design interfaces as abstract as possible • Abstraction allows reuse • Foundation of many design guidelinesOO Programming - Introduction is licensed under a Creative Commons Attribution- 19NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Think Abstractly Which interface is more abstract? 1 public class Computer { public void positionDiskHead(int sector) { } public void startDiskRotation() { } public Byte[] readBytes(int endSector) { } public void endDiskRotation() { } } 2 public class Computer { public Byte[] readFromMedium(MediumIdentifier id, ReadInstructions instructions) { return null; } }OO Programming - Introduction is licensed under a Creative Commons Attribution- 20NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Think Abstractly Which interface is more reusable? 1 public class Computer { public void positionDiskHead(int sector) { } public void startDiskRotation() { } public Byte[] readBytes(int endSector) { } public void endDiskRotation() { } } 2 public class Computer { public Byte[] readFromMedium(MediumIdentifier id, ReadInstructions instructions) { return null; } }OO Programming - Introduction is licensed under a Creative Commons Attribution- 21NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possibleOO Programming - Introduction is licensed under a Creative Commons Attribution- 22NonCommercial-ShareAlike 3.0 Unported License.
  • You Ain’t Programming OO Gonna Need It Minimal interface • Tend to follow the YAGNI principle • Give clients only the strictly needed interfaces • Only add new interfaces if object’s clients really require itOO Programming - Introduction is licensed under a Creative Commons Attribution- 23NonCommercial-ShareAlike 3.0 Unported License.
  • Programming OO Minimal interface I give this interface to the client of my object. (In reality, I’m giving no1 interface at all) public class Computer { }2 The client asks, “Hey, now what? How do I turn it on?” I give an interface to allow the client to turn on the computer3 public class Computer { public void turnOn() {} }4 The client then asks, “Thanks, but… How do I turn it off?”5 Story goes on…OO Programming - Introduction is licensed under a Creative Commons Attribution- 24NonCommercial-ShareAlike 3.0 Unported License.
  • OO Concepts • Encapsulation and Data Hiding • Inheritance • Polymorphism • CompositionOO Programming - Introduction is licensed under a Creative Commons Attribution- 25NonCommercial-ShareAlike 3.0 Unported License.
  • OO Concepts Encapsulation and Data Hiding • Hide implementation details, such as state and behavior pertaining only the implementation of interface. • Give users only access to interfaces public class Computer { private PowerSupply powerSupply; public void turnOn() { What a user see turnOnPowerSupply(); } public void turnOff() { turnOffPowerSupply(); } public class Computer { public void turnOn() { private void turnOffPowerSupply() { turnOnPowerSupply(); powerSupply.turnOff(); } } public void turnOff() { private void turnOnPowerSupply() { turnOffPowerSupply(); powerSupply.turnOn(); } } } }OO Programming - Introduction is licensed under a Creative Commons Attribution- 26NonCommercial-ShareAlike 3.0 Unported License.
  • OO Concepts Inheritance • Allows me to reuse code by abstracting common behavior and state of a set of classesOO Programming - Introduction is licensed under a Creative Commons Attribution- 27NonCommercial-ShareAlike 3.0 Unported License.
  • OO Concepts Polymorphism • I can have a have a type that assumes multiple forms ElectronicEquipment computer = new Computer(); ElectronicEquipment phone = new Phone(); computer.turnOn(); phone.turnOn(); • An ElectronicEquipment can assume the form of a Computer or a Phone • A user with a reference to an ElectronicEquipment don’t care if it’s a Computer or a PhoneOO Programming - Introduction is licensed under a Creative Commons Attribution- 28NonCommercial-ShareAlike 3.0 Unported License.
  • OO Concepts Composition • Can reuse code by factor in common behavior and state to a separate class and use that class as a building block of other classes. – Both Printer and Computer have a PowerSupply and a motherborad.OO Programming - Introduction is licensed under a Creative Commons Attribution- 29NonCommercial-ShareAlike 3.0 Unported License.
  • João Pereira March 2012OO Design Principles - Introduction by João Miguel Pereira is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 3.0 Unported License.