120 likes | 284 Views
Object Oriented Design. What is it? Why do it? Simon Woodworth, 19 August 2004. Introduction. Purpose of this presentation Explain what Object-Oriented Design (OOD) is Explain why it is important as a design and programming methodology OOD is important because …
E N D
Object Oriented Design What is it? Why do it?Simon Woodworth, 19 August 2004 Simon Woodworth
Introduction • Purpose of this presentation • Explain what Object-Oriented Design (OOD) is • Explain why it is important as a design and programming methodology • OOD is important because … • It allows complex programming projects to be broken down into more mangeable sections • It reduces the cost of maintaining software
Object:Red Setter Object:Labrador Object:Terrier Object:Bulldog What is Object-Oriented Design? • It promotes thinking about software in a way that models how we think about the real world • It organises program code into classes of objects Class: Dog • Every object is an instance of a class • Every object has attributes and behaviours
What is a Class? • A class is a collection of things (objects) with similar attributes and behaviours. • For example: • Dogs • Attributes: Four legs, a tail • Behaviours: Barking • Cars • Attributes: Four wheels, engine, 3 or 5 doors • Behaviours: Acceleration, braking, turning
What is an Object? • An object is a specific instance of a class • For example: • Volkswagen is an instance of the Car class • Attributes (what it looks like): • Blue • Front wheel drive • Max speed 115 mph. • Behaviours (what it does): • Accelerate • Turn • Stop
In programming terms … • A class is a section of program code that defines how to create and use a specific group of objects. • It’s a template for creating new objects • An object is a specific instance of a class and has its own place in computer memory • Its attributes are stored as data values • Its behaviours are defined by program code • Every object is different – even if they look exactly the same! • For example: My blue Volkswagen is not the same as your blue Volkswagen
Classes and Objects:An Example Object: Alice’s Account Attributes:Name = AliceNumber = 04701Balance = €1003.22 Behaviours:WithdrawLodge Class: Account Attributes: NameNumberBalance Behaviours:WithdrawLodge Object: Bob’s Account Attributes:Name = BobNumber = 28804Balance = €81.66 Behaviours:WithdrawLodge
Why is this important? • It models how we view the real world • Humans tend to categorise what they see into groups • Even very small children do it • Reduces cost of software development • Large complex projects can be subdivided into classes • Reliability – the workings of objects can’t be interfered with • Classes can be reused in other projects • Classes can be maintained without rewriting other program code • Introduces new programming concepts • Encapsulation • Inheritance
Object Oriented Design Concepts • Encapsulation • We can hide how an object works from other parts of the program • Increases reliability because the internal workings of objects are protected from interference • Allows us to reuse objects in other programs because their behaviour and attributes are well-defined • Allows us to change the way an object works on the inside without changing the way it looks on the outside • Example: Car Stereo • Standard case size and fittings, regardless of features • Can be upgraded without affecting rest of car
Object Oriented Design Concepts • Inheritance • We can create new classes of objects by inheriting attributes and behaviours from existing classes and then extending them • No need to reproduce or duplicate work done in creating original class • We can build hierarchies (family trees) of classes • Example: Rally Car • Inherits properties of class Car … • … and extends class Car by adding a rollcage, racing brakes, fire extinguisher, etc.
Conclusion • Object Oriented Programming Languages: • Java, C++, Visual Basic .NET, C# • Object Oriented Design allows us to create program code that is : • Reusable • Adaptable • Maintainable • Reliable