S.O.L.I.D. in UnrealScript

Discussions about Coding and Scripting
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: S.O.L.I.D. in UnrealScript

Post by Higor »

At C++ level, interfaces are not-so-simply a variation of multiple inheritance (single can be the case too), where you attach a new virtual function table.

Example at native level in Unreal Engine:

Code: Select all

class Player extends Object
	native noexport;

var native const int vfOut;
var native const int vfExec;

// The actor this player controls.
var transient const playerpawn Actor;
var transient const console Console;
//etc...
This is the native definition of Player:

Code: Select all

class ENGINE_API UPlayer : public UObject, public FOutputDevice, public FExec
{
	DECLARE_ABSTRACT_CLASS(UPlayer,UObject,CLASS_Transient|CLASS_Config,Engine)

	// Objects.
	APlayerPawn*	Actor; // O=48
	UConsole*		Console;
//Etc...
The unrealscript version is supposed to mirror the native version variable-by-variable, otherwise the structs end up having different sizes.
You can see that the UScript version has two additional vars: vfOut, vfExec.
Those are the virtual function table pointers for FOutputDevice and FExec classes, which in this case can be considered 'interfaces'.
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: S.O.L.I.D. in UnrealScript

Post by Feralidragon »

I just checked the C++ headers, and those 2 have virtual functions and do seem indeed to act like interfaces, which then UPlayer "implements".
Although my own knowledge of C++ is baby-tier at best, so I had to recheck what the virtual functions were all about. :lol2:
But knowing what those "vf" vars mean in UScript and why they are there is certainly very interesting to know, thanks for the info. :mrgreen:

But yeah, C++ doesn't really have the concept of interfaces like other languages, given that it doesn't really need one, given that it has virtual functions and allows for multiple class inheritance directly.
After all, "interfaces" were created in other OOP languages as something close to a workaround on their inability to support multiple class inheritance directly due to the diamond problem, so "interfaces" were just a nice way to allow something close to multiple inheritance with only virtual functions forcibly, since that was the trait mostly needed anyway so that any qualities and capabilities could be shared and recognized between unrelated classes.
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: S.O.L.I.D. in UnrealScript

Post by Feralidragon »

The fifth, and last, principle (DIP) is done and up: viewtopic.php?f=15&t=12753&p=105376#p105376

And with that, all SOLID principles are done.
If anyone has any doubts, or even any criticism, either on the principles themselves or how I explained them, or any mistakes I may have made, please do not be afraid, just go ahead and ask or tell whichever is in your mind. :)
Post Reply