7.1P Answer - 7.1 task PDF

Title 7.1P Answer - 7.1 task
Course Object-Oriented Programming
Institution Swinburne University of Technology
Pages 5
File Size 327.8 KB
File Type PDF
Total Downloads 10
Total Views 354

Summary

OBJECT-ORIENTED PROGRAMMINGObject-oriented programming (OOP) is designed which focuses on data (more likely on coupling) rather than action and logic. It is the bottom-up approach.In Object-oriented, A class is the core of any modern OOP languages that allows decomposition of a problem into several ...


Description

OBJECT-ORIENTED PROGRAMMING

Object-oriented programming (OOP) is designed which focuses on data (more likely on coupling) rather than action and logic. It is the bottom-up approach. In Object-oriented, A class is the core of any modern OOP languages that allows decomposition of a problem into several entities call object. It is mandatory to create a class for representing data. A class is a blueprint of an object than include variables for storing data and method to perform an operation on the data. For example, a car has registration number, colours, and body size. A car can move which is a method. An object is a real-world entity, for example, a car, an animal etc. An object has fields which know things and method which do things. In other words, object is an entity that has state and behaviour. A program may create many objects of the same class. Objects are also called instances. In C#, a program consists of multiple objects that interact dynamically. To be able a good design software, we need to understand about classifications, roles, responsibilities, and collaborations of objects. A role is a set of responsibilities and responsibility is a task which an object should do. So, an object has many responsibilities such as know its fields and has its own method. Collaboration is the relationship between classes. If the objects do not collaborate in a program, nothing can be achieved. Objects collaborate with each other by sending a message. A field is a variable of any type that is declared in a class. A field is used to store data about the class. Afield can be given an initial value by using the assignment operator when the field is declared. Generally, a field is used only for variable that have protected or private accessibility. For example, a car has register number. So, register number is a field for a car. A method is a block of code that contains statements and perform a task together. So, task is performed when we call the method. Every program has at least one method called Main. Input value can be given from arguments or parameters. For example, a car can move. So, move is a method for car.

High cohesion means there is a separate class for all methods to execute a specific job, which is easier for maintenance. Low cohesion only one class is responsible to execute lots of methods. So that it is not easy for reusability and maintenance. The coupling is the relationship between objects. Tight coupling means classes and objects are dependent on each other. Tight coupling is not good because it is not flexible or not re-usable of the code. Loose coupling means make fewer dependencies of a class so that uses the different class. Another important concept in OOP is the interface. The interface helps to avoid using overuse of inheritance. it specifies what the class must do but not how. it also a blueprint of the class. The interface is used to achieve abstraction. To become a master in Object-oriented Programming. We need to understand four principles Abstraction, Encapsulation, Inheritance, and polymorphism Abstraction is about hiding unwanted details while showing most essential information. Abstraction helps to reduce the complexity of the design and implementation process of software. Abstraction solves the issues at the design level. And it allows focussing on what the information object must contain. So, it is to classify the different kind of roles objects in the program. Once we have modelled the object using Abstraction, the same set of data could be used in different application. For example, in 4.1P task in Line class, when SplashKit.DrawLine method from SplashKit library is called to draw the line. It is essential to provide DrawLine option to draw the line. Encapsulation means wrapping code and data together into a single unit, for example, a capsule which is mixed with several medications. We can use getter and setter method to set and get the data in it. It also hides the value and state of the data object that prevent unauthorized parties’ direct access to them. encapsulation is a method to protect information from outside. Inheritance is one of the most important concepts in object-oriented programming that inherit the parent class from the child class. This also provides an opportunity to re-use the code and functionality. it is used to achieve polymorphism, but the purpose of inheritance is to re-use the code. Inheritance means an “is-a” relationship between classes.

Polymorphism is one of the pillars of OOP. Poly derives from a Greek word which means “multiple forms”. Polymorphism is one of the ObjectOriented Programming features that enable to perform one action in multiple different ways. Polymorphism occurs when we have many classes that related to each other by inheritance. Every child class inherit methods and properties from the base class. Polymorphism uses this method to do different tasks. In this way, a single action can be performed in many ways. Polymorphism example can be found in our weekly task.

In this example, polymorphism occurs when the Shape class (parent class) reference is used to refer to a child class MyCircle, MyRectangle, Line. One of the techniques in polymorphism is overriding, where the method or properties with the virtual or abstract keywords in parent class. That can be overridden in a child class. For example, in Shape Drawing task an abstract Shape class is a parent class which also have an abstract DrawOutline method that is overridden in MyRectangle, MyCircle and Line class using override keywords with their own implementations In this subject, I have used all four principles in my ShapeDrawing program. I used Encapsulation and Abstraction by using private access to the fields and properties. I have used encapsulation to prevent access to other object or setting data. Inherit MyCircle, MyRectangle, Line class from the parent class Shape, so it can re-use the method or property. Inheritance also creates Polymorphism in my programme that instant an object like a MyRectangle,

MyCircle or Line, we declare it as Shape Class.

Another example of OOP is the SwinAdventure programme, the programme is based on Console application. The name and description of the GameObject were assigned as private access. The Item and Player classes were inherited from parent class GameObject class, the bag class inherit the parent class Item. So, Object-oriented programming is one of the most useful programming in modern technology that can handle a huge amount of codes.

Reference: C++ Home Sept 17th 2020, Object-Oriented Programming, CPP, viewed 1 October 2020, < http://www.cpp-home.com/archives/206.html>.

Microsoft 2017, C# Programming Guide, Microsoft, viewed 7 October 2020, https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/....


Similar Free PDFs