2_objects - Object Oriented Programming OOP Principles Java...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Object Oriented Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
! OOP Principles ! Java Classes ! C++ Classes w September 2004 w John Edgar w 2
Background image of page 2
! Colours ! How should we work with colours? How should we store them? How should we modify or operate on them? ! Linked lists ! How should we provide the functionality of a linked list? ! Shapes ! w September 2004 w John Edgar w 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
! Encapsulation ! Color Class ! Designing Classes ! Inheritance ! Polymorphism w September 2004 w John Edgar w 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
! Let's say we need to represent colours ! There are many different colour models ! One such is the RGB (red green blue) model ! RGB colours ! A colour is represented by three numbers, which represent the amount of red, green and blue ! These values are sometimes recorded as doubles (between 0.0 and 1.0) or sometimes as ! Integers, between 0 and 255 (or some other number) How many colours can be represented? w September 2004 w John Edgar w 6
Background image of page 6
w September 2004 w John Edgar w 7 255,0,0 0,0,255 0,255,0 0,0,0 255,128,0 255,255,255 128,128,128 128,128,192
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
! We need three variables to represent one colour ! It would be convenient to refer to colours in the same way we refer to primitive types ! Object Oriented Programming (OOP) organizes programs to collect variables and methods ! A class is a factory (or blueprint) for creating objects of a particular type ! An object is a collection of variables and methods, and is an instantiation of a class Color c = new Color(); w September 2004 w John Edgar w 8 class object constructor
Background image of page 8
! An object combines both variables and methods in the same construct ! Variables give the structure of an object ! Methods dictate its behaviour ! A class should be a cohesive construct that performs one task (or set of related tasks) well ! Objects can be used as if they were primitive types ! To encapsulate means to encase or enclose ! Each object should protect and manage its own information, hiding the inner details ! Objects should interact with the rest of the system only through a specific set of methods (its public interface) w September 2004 w John Edgar w 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
! The class describes the data and operation s ! For colours these include: Attributes for red, green and blue Methods to access and change and create colours ! An individual object is an instance of a class ! Similar to the way that a variable is of a type ! Each object has its own space in memory, and therefore each object has its own state Individual Color objects represent individual colours, each with their own values for red, green and blue w September 2004 w John Edgar w 10
Background image of page 10
! Using objects can aid design ! People are used to the idea of everyday objects having states and behaviours ! This idea can be applied to components of a program ! OOP also promotes modular design where modules are: ! Highly cohesive and ! Loosely coupled w September 2004 w John Edgar w 11
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
! To achieve loose coupling, classes are only allowed to communicate through their interfaces ! Thereby hiding their implementations details
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 60

2_objects - Object Oriented Programming OOP Principles Java...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online