Coder Social home page Coder Social logo

pewpew-in-space's Introduction

OOP-theory-demo: PewPew in Space

This mini game is a demonstration of my knowledge regarding the four pillars of Object-Oriented Programming.

Abstraction:
Replacing blocks of code with methods in the update and trigger/collider methods to hide some of the calculations and conditional branches with abstract method names that explain their function but hide the messier looking code, therefore increasing readability and reusability.

Encapsulation:
Using get and set accessors to control access to and/or verify certain values. An example of this would be where you have a variable that can be read by other scripts but only written to within its own script. Another example would be where you only want to set a variable with positive numbers, but not negative numbers; you could use an if branch to only allow numbers equal or greater than zero to be assigned to the variable and return an error on anything else.

Inheritance:
Instead of writing out the same code for multiple similar objects, you can create a child class from a parent class, having the child class use the code from the parent class and then building on top of that. This way sibling classes can differentiate from each other yet still share much of the same code. This is done using the Class : Parent notation when declaring the class. The protected keyword (an example of encapsulation) allows you to share access to inherited scripts

Polymorphism:
When using inheritance you can modify or override the parents code (using the virtual and override keywords) allowing you to use parts of the parent code but not all, or even change inherited code. You can also use polymorphism to overload a method with multiple different parameters, for example a method that applies a color to an object could be given a color parameter or individual R, G, B integers as parameters.

pewpew-in-space's People

Contributors

synith avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.