Please enable JavaScript.
Coggle requires JavaScript to display documents.
Object-Oriented-Programming - Coggle Diagram
Object-Oriented-Programming
Classes and Objects
A class is the basic building block of OOP. It specifies attributes(properties) together with behaviours(Methods)
An object is a specific member of a class. OOP allows a developer to define their own classes. Whenever the programmer then creates an object, it is built according to the pattern of the class it belongs to. The definition of a class will specify:
The attributes(properties) of each member
The behaviours(methods) that are allowed on each member of the class
Class Attributes
Each attribute is defined as a variable of an appropriate type. For example: If we were to make a class 'Car' and wanted to add 6 properties to it. After defining each attribute, we can make 'Car' objects, each of which will have its own personal set of attributes
Class Behaviours
Behaviours are the actions we are able to perform on the objects of a class, these are called methods. When dealing with methods, we need to understand parameter lists, they describe what additional information is needed for the method to work properly
Encapsulation
Where the technical attributes of a class and its behaviours are hidden within the object, so data can only be changed by using an appropriate method, this is enforced through the 'private' term.
We can define a method which allows us to inspect the current value of a specific attribute of an object(get method), and a method which allows us to alter the value(set method)
Inheritance
The mechanism in which the attributes and behaviours of a class can be shared or inherited by a new, more specialised class derived from it. The original class is called a superclass, the new subclasses are more specialised versions of it and are called subclasses.
Evaluation
Advantages:
More accurate modelling - represents the real world more realistically than other programming methods
Reuse of code leads to improved productivity as the subclass inherits the code from its superclass
Reuse of code leads to improved productivity as the derived classes don't need to be tested apart from new methods as the code is tested in the superclass
Disadvantages:
It is not suitable for all applictions