Day 21. Cutscene. Abstract Classes & Interfaces
Ok, my laptop is 9 years old MacBook Pro. It has an i5 processor, integrated video, 8Gb ram, and SSD. It is a reliable machine. Unfortunately, it is not a good fit for the Cinematography course. Difficulties I experienced with lighting, it takes some quiet time to change anything that requires lighting recount. I can edit the game, but can not play it. Getting 502 error. Instead, I am doing Crash course C# and improve my version of Space Shooter in parallel. I also will try those challenges to test my knowledge.
Ok, this is what I learned today. Mostly repetition about OOP.
Abstract Classes. They define class on a peak of hierarchy. They are work as a template. Also used for methods and functions. It is pushing for a developer to implement written methods if a class was inherited. Methods also can be virtual. That means it can have operators in the abstract class. Virtual methods can be overridden in a child class.
Example: Different kinds of Enemy usually have Attack and Die methods as a must. That can be insulated to a new script with an abstract class named Enemy. When a new class inherits an abstract class, the developer will know what to do with those methods that must and not skip it.
Interfaces. Interfaces can be used as a combined class. Attached to inherited class. It is named like this IDamagable, IShot, and so on. It works like a protocol. What needs to implement for damage function? Connect the interface. It will show methods and variables to use.
Polymorphism. Interfaces can be used for it. To avoid filtering with an “if” statement it is sometimes better to use polymorphism of Interfaces if method defined in it.
Generic Interfaces. It is about a type of receiving parameter in the function. If you don’t know what type will be passed and they are kind of the same processing, just put T instead inside the function. Later when a programmer will use your method, put <int> and so on when the function is called.
Game Programming Design Pattern: Singleton
So, in-game dev it is easier to get it if you heard about UI and Spawn Manager. They are only one for the whole game and can be turned into a singleton. The effect of it will availability of the method of that class. So, you will no need to define the script at the start. It can be awake on game load. Something like this will be available with singleton GameManager.Instance.DisplayName();