OOP Principles PDF

Title OOP Principles
Author Aaryan Pujara
Course Object-Oriented Programming
Institution Swinburne University of Technology
Pages 5
File Size 108.1 KB
File Type PDF
Total Downloads 22
Total Views 90

Summary

OOP PrinciplesA guideConcepts and PrinciplesABSTRACTIONAbstraction is used to make the complex structures simple and more efficient by using a simple interface such as UML diagrams. It explains the structure andfunctions of the objects in the program. It ​is a process where you show only“relevant” d...


Description

OOP Principles A guide

Concepts and Principles ABSTRACTION Abstraction is used to make the complex structures simple and more efficient by using a simple interface such as UML diagrams. It explains the structure and functions of the objects in the program. It is a process where you show only

“relevant” data and “hide” unnecessary details of an object from the user. We have used abstraction a lot of times in this unit, for example we have used the fillrectangle function from SplashKit library without even knowing how it works. ENCAPSULATION It is the principle of hiding any piece of code that is not necessary for every class to know about, to keep the program simpler. This can be done by making classes or generating private fields so that if we need to fix a portion of code the whole code doesn't need to be changed. We have practiced encapsulation a lot of times in this unit, for example in pass task 2.2 we used encapsulation in shape class to declare color, x, y etc. as private. INHERITANCE In OOP we try to keep the codes clean, by which we don't have to write them again and again. Inheritance helps in this by sharing properties and fields declared in one class among the other classes to keep the code simple.

There are two kinds of classes related to inheritance:

-

Child Class: The class that extends the features of another class is known as child class, subclass or derived class.

-

Parent Class: The class whose properties and functionalities are used(inherited) by another class is known as parent class, super class or Base class.

A parent class gives its fields and properties to the child class to keep the code clean so that we don't have to write the same piece of code again and again. We have practiced inheritance a lot of times in this unit, for example in task 4.1 the shape which is a parent class shares info with child classes that are line circle and rectangle because they all have the same properties.

POLYMORPHISM It means many forms, this makes the objects to be polymorphic like strings, int, shapes etc depending on the information being passed. There are two types of polymorphism, Static and Dynamic. This makes the program more adaptive and easy to work with. - Static It is also referred to as compile-time polymorphism and i s done using method overloading and operator overloading. - Dynamic It also is referred to as run-time or late binding polymorphism and is done using method overriding. In task 4.1 we used ```virtual``` and ```override``` keywords to make them dynamical. For example in 4.1 tasks all the shapes can be defined as a single shape type and storing them in the same list of shapes. ROLES

It is the role of every object in a program, it helps to sort between the objects by looking at what roles specific objects play.

RESPONSIBILITIES This is about what the objects know and do, every object is given a responsibility that it needs to have in the program. COLLABORATIONS In OOP none of the objects needs to do all the things, it is the idea of making objects communicate with each other to do a task by collaborating. For example in Task 8.1 the List in Golfer class is a practice of collaboration. COUPLING It is the relationship of two classes to each other, and defines how much one is dependent on the other. A tightly coupled class is bad as a change in one will result in crashing of another whereas a loosely coupled is a one where there is almost no impact of changing either of classes on another which is good. For example in task 8.1 which was the semester test, changes in putter class had no impact on sandwedge class whatsoever and vice versa. COHESION It is the principle of how a class does its job. Its main function is to make sure a class is working properly and efficiently towards a given task. The more efficient the class the more the cohesion, and the higher the cohesion the easier it is to handle the whole program. For example in the clock task the sole purpose on time() object was to read and print time.

Programming Artefacts CLASS

These are the blueprints to build a specific type of object. It is a basic concept of Object-Oriented Programming. METHOD It is the function an object can do, it can be defined as: ● Public ● Private OBJECT It is a part of a class template and it does things that are defined by the class, it consists of methods and properties to make a particular type of data work. FIELDS It is a variable of any type that is declared directly in a class. A class or struct may have instance fields, static fields, or both. INTERFACE In object-oriented programming, an interface gives a set of functions and signatures also hides the implementation of those functions in an implementing class. Interfaces form a contract between the class and the outside world. A  n interface looks like a class, without implementations. The only thing it contains are declarations of events, indexers, methods and/or properties. They are inherited by structs and classes and give an implementation for each interface member declared. They're great for putting together plug-n-play like architectures where components can be interchanged at will. I n task 5.1 we used interface in IHaveInventory class.

REFERENCES

● https://www.codebyamir.com/blog/interfaces-in-object-oriented-design ● https://www.geeksforgeeks.org/cohesion-in-java/ ● https://gamedevelopment.tutsplus.com/tutorials/quick-tip-the-oop-principle-ofcoupling--gamedev-1935 ● https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/ ● https://beginnersbook.com/2013/03/inheritance-in-java/

Thank You!...


Similar Free PDFs