PDF Object-Oriented Programming Concepts
Document Details

Uploaded by InterestingHeisenberg
Tags
Summary
This document explores key concepts in object-oriented programming (OOP) using UML diagrams. Topics include classes, objects, data types, and relationships such as association and inheritance. The document provides examples and definitions to help understand the core principles of OOP.
Full Transcript
UNIT 5 – SL D1 1.1 Object – an abstract en;ty that describes the data that this en;ty has and the ac;ons that this en;ty can perform It can correspond to real-world en;;es, has helped in the evolu;on of good design prac;ces, and is a core aspect of OOP 1.2 Class – abstract ob...
UNIT 5 – SL D1 1.1 Object – an abstract en;ty that describes the data that this en;ty has and the ac;ons that this en;ty can perform It can correspond to real-world en;;es, has helped in the evolu;on of good design prac;ces, and is a core aspect of OOP 1.2 Class – abstract object en;;es Someone needs to build a specific object of a class before the object can be used Calling methods – sending messages to an object in order to perform ac;ons in OOP Every specific object cannot perform ac;ons but also has some specific data Every specific object has data that are specific to the object and accompany it throughout the execu;on of a program Classes, from which specific objects can be instan;ated, do not occupy any memory in a program Blueprints Classes do not occupy memory space in a program; a specific object that is instan;ated from the class occupies enough memory to accommodate the object’s data and ac;ons 1.3 Unifies modeling language (UML) – provides a way to visualize the design of any soVware system and has evolved into the standard for modeling object-oriented programs - Defines the number of different types of diagrams, but only the class diagram is within the scope of this book - Not the same as flow charts (UML diagrams) UML ac>vity diagram – considered as a modern extension of flow charts, and as such, UML can be thought of as a superset of flowcharts UML class diagram – the goal of this diagram is to depict the classes within an object-orientated program, as well as their collabora;ons - It illustrates classes as three-;er compartments, rectangles divided into 3 compartments These ac;ons are presented in the returnType: ac>onName(inputType) form. inputType – type of data that is required by the specific ac;on returnType – a type of data that is returned by the specific ac;on aVer it has completed its execu;on - if it’s missing, that depicts an ac;on that does not return any data UML class diagrams depict classes but also display how those classes collaborate Classes within an object-oriented program are connected in various ways, and UML class diagrams represent those connec;ons à they describe the sta;c structure of the system Associa>on – a line connec;ng the two classes Since UML class diagrams can become quite complex as programs increase in size and incorporate more classes, informa;on can be a\ached to these associa;ons to make things easier Each associa;on has 2 roles, and each role has a direc;on The role does not have to be explicitly named à it’s given a name to make things clearer Associa;ons between classes also have mul;plici;es – these are placed at each end of an associa;on line and indicate the number of objects of one class linked to one object of the other class Inheritance - the mechanism that takes advantage of similari;es - Inheritance can be thought of as an is-a or is-is-like rela;onship In UML class diagrams, inheritance is displayed with hollow arrows UML class diagrams can also be created using just the names of the classes that par;cipate in the diagram UML class diagrams are created in this manner to focus on the associa;ons, roles, mul;plici;es, and inheritances that take part between the classes and not on the actual data or ac;ons that each of these classes may contain 1.6 Descrip;on of UML class diagram was used to depict how various objects associated with each other, as well as how some classes could inherit data and ac;ons from other classes that were termed generaliza;ons 4 rela;onships in UML diagrams: associa>on, dependency, aggrega>on, inheritance ASSOCIATION Simplest rela;onship between 2 or more objects One or two role labels may be presented to signify the type of associa;on that takes place between the two objects DEPENDENCY – “USES“ RELATIONSHIP This s. “““ignifies that one object is dependent on one or more objects in order to func;on The implementa;on of an object depends on one or more other objects This occurs when one class links to one or more classes Represented with the dashed arrow à the arrow leaves the object that depends on the object that the arrow points to This can be described as “a client uses a supplier“ AGGREGATION The aggrega;on rela;onship signifies that one object belongs to another object and no other There is a parent and a child object – the child object cannot belong to another parent object The lifecycles of the parent and the child object are independent Example – can be seen in the UML class diagram Aggrega;on is said to be “has“ a rela;onship A hollow diamond followed by a line represents the aggrega;on rela;onship INHERITANCE The inheritance rela;onship (a.k.a generaliza;on) signifies that one object (a.k.a child or subclass) is a specialized form of another object (a.k.a parent or superclass) “is a” rela;onship A hollow triangle followed by a line represents the inheritance rela;onships 1.7 Dependencies between objects are what the name suggests: when one object uses another object, the first object depends on the second since it cannot func;on without it Dependencies are direc;onal, in that an object can depend on another object, but the second object does not necessarily need to depend on the first object as well Ex. If object A depends on object B, it does not necessarily mean that B also depends on A Finding the solu;on using object-oriented programming involves dealing with a number of interdependent objects Dependencies decrease the ability of code reuse, as well as increase maintenance overheads 1.8 1.9 DATA TYPES Data types – allow programs to classify these data into different types – crucial as to the meaning of the data, as well as to how they can be stored and manipulated Common data types: integer numbers, real numbers, Booleans, and strings INTEGER NUMBERS Represents a finite subset of the mathema;cal integers Can include nega;ve values Depending on the hardware and programming language used, every integer is represented by a specific number of bits REAL NUMBERS Represents numbers that contain frac;onal values Computers represent the approxima;on of real numbers with a trade-off between range and precision Two primi;ve data types that can represent floa;ng point numbers: float and double Double has more precision and can represent larger numbers than float BOOLEANS Represent only two possible values, true/false STRINGS Represents a series of characters and is mainly used to display informa;on Ex. String s=2this is a string” – would build a new String object that could be used to display the informa;on between the quotes to the user 1.10 Parameter – the name of the informa;on that is used in a method, func;on or procedure Argument – the value that is passed into a method, func;on, or procedure