Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Programming Concepts. Object Oriented Programming Type of programming whereby the programmer defines the data types of a data structure.

Similar presentations


Presentation on theme: "Object Oriented Programming Concepts. Object Oriented Programming Type of programming whereby the programmer defines the data types of a data structure."— Presentation transcript:

1 Object Oriented Programming Concepts

2 Object Oriented Programming Type of programming whereby the programmer defines the data types of a data structure the type of operations (methods/functions) that can be applied to the data structure In this way the data structure becomes an object that includes both data and methods or functions OOP allows developers to create reusable objects that interact with each other. Uses the ‘bottom-up’ approach

3 Class A "Class" is a template or blue print which defines the attributes (properties) the actions or methods which can be performed upon those attributes for a given type of entity. E.g. Snake can be a class attributes: avgNoOfEggs, colour, length, dob methods: how it eats its prey (eats it whole) how it moves (uses tummy muscles)

4 Sub Class The class at the top of the hierarchy of classes is known as the super class. Classes that derive from this class are known as subclasses or child classes. E.g. Constrictor is sub class of Snake Venomous is sub class of Snake

5 Inheritance snake Constrictor Boa Constrictor Anaconda Venomous cobraviper

6 Object An object is an "Instance" of a Class. The class definition is used to create "Instances" of the class, which are the actual objects used within your application. Objects define what it knows and how it functions E.g. class: Snake Object 1 : Cesar is an instance of the Boa Constrictor class which is in turn a subclass of Constrictor and inherits from Snake

7 Encapsulation The process of combining data and methods together in one class. It means ‘Packaged together’. Encapsulation is implemented in Java through access modifiers. Parts of the object are accessible to other objects and some parts remain hidden

8 Public Class Snake Private snakeName As String Private dob As Date Public Sub New() End Sub Public Sub New(ByVal sname As String, ByVal sdob As Date) snakeName = sname dob = sdob End Sub Public Sub setSnakeName(ByVal sname As String) snakeName = sname End Sub Public function getSnakeName() as string return snakeName End Sub End Class

9 Inheritance Is when objects derive attributes and behaviours from other objects Reduces the amount of new code required to implement a system Allows new objects to be created from old objects E.g.Class Snakes Each object created from class Snakes inherits ‘lays eggs’ attribute from Snakes

10 Polymorphism Polymorphism literally means “many forms”. It means that different objects respond to the same message with different methods. Polymorphism takes advantage of inheritance and interface implementations.

11 Polymorphism Constrictors versus Poisonous Snakes All snakes KILL but the way they kill their prey is different!! What action common to all snakes but carried out differently depending on the type of snake?

12 Polymorphism Both sub classes inherit the method signature i.e. method name and parameters must be the same but the actual coding will be different E.g. Venomous Snakes kill using their fangs / venom Constrictors kill their victims by suffocating them

13

14 How does memory management work with components on a form? Dim myButton(10) As Button For i=0 to 10 myButton(i) = New Button myButton(i).Top=i*10 myButton(i).Left= 100 Next 101Button Code 100Button Code 39100 38myButton(4) properties 37myButton(4) properties.. 437 3 2 1 0 i is pointer to location of address

15 Advantages of OOP Isolation of objects from one to another Objects can only communicate through known means One object is unable to influence the internal operations of another object Objects support the idea of ‘off-the-shelf’ or ‘plug- in’ software components Adds more speed or functionality without effecting the operation of the system as a whole Software maintenance becomes easier


Download ppt "Object Oriented Programming Concepts. Object Oriented Programming Type of programming whereby the programmer defines the data types of a data structure."

Similar presentations


Ads by Google