Saturday, February 28, 2015

The summary of Object-Oriented Programming #Week6 (to be graded)

In the csc148 class, we learned a new method of programming, which is Object-Oriented Programming (OOP). At the beginning of the class, I was struggling in the Object-Oriented Programming because it is a new concept and I had totally no idea what it is. Fortunately, a couple of weeks later, I made sense about the Object-Oriented Programming.

BASIC CONCEPTS ABOUT OOP

There are some concepts about object-oriented-programming:

What Is an Object?
An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner.
What Is a Class?
A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior.
What Is Inheritance?
Inheritance provides a powerful and natural mechanism for organizing and structuring your software. This section explains how classes inherit state and behavior from their superclasses, and explains how to derive one class from another using the simple syntax provided by the python programming language.
What Is an Interface?
An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. This section defines a simple interface and explains the necessary changes for any class that implements it.


A SIMPLE EXAMPLE ABOUT OOP:
For example, we are trying to make a small RPG game. So how do we start it?
Well, there are some monsters and heroes in this small game. They can attack each other with different skills (try to compare this game with Pokémon).


First of all, we need to create a class which called "Heroes" and each hero has the features of blood, age, and name. In addition, do not forget create a class of monsters.

Here's the code:




Well, now we have finished creating classes, it’s time to create some objects.

hero1 = Heroes(100, 20, 'Lee', 'Fire')

The hero called Lee, he has 100 blood, and he is 20 years old, and he can use fire


monster1 = Monsters(50, ‘Snoopy’, ‘Bite’)

The monster called Snoopy, he has 50 blood, and he can bite someone.

Image if you want to create thousands of monsters and heroes in the game and if you do not know how to use object-oriented-programming, that will be very tough for creating the game. However, if you know how to use OOP well, you can make a flexible combination for each object and that will save your time.


CONCLUSION:


Object-oriented-programming is significant and useful for programmers especially for creating the Role Play Games and there are several reasons, which are easy to maintain, easy to extend, efficient. Firstly, the idea of using OOP has a higher readability because of the existence of the inheritance. Even though the requirements need to be changed, the maintaining can be only working with local models. Therefore, it is convenient and low-cost to maintain a program if we use the concept of OOP. Secondly, because of the features of inheritance, encapsulation, and polymorphism, we can design naturally out a well-structured computer system with high cohesion and low coupling. Finally, when we write code, we can create abstractions of objects from the real world according from our demands. Using this concept for addressing programming problems is close to our daily life and the natural thinking, therefore, there is no doubt that it can enhance the quality of code and the efficiency.





No comments:

Post a Comment