Good afternoon,
I am not sure how to describe the process that I ask correctly in one sentence, so please excuse the title. I was looking for a way to ensure that base class and interface users will assign data that will be considered by the object itself and other non-default objects. So I did the following:
struct ExampleInterface { virtual void SomeMethod() = 0; virtual std::string WhatLooksLikeAGetterButIsNot() = 0; };
Here is an example of the real world:
//So states can be "poped in and out".// struct State { //To retrive what the active state is called.// /*Code In Question--->*/virtual std::string RegardStateAs() = 0;/*<---Code In Question*/ virtual void ExecuteState( VRGE::MDNode* metaData ) = 0; };
The idea would be to end up doing something like A (This option helps prevent the problem if someone comes from "Update"):
struct Update : public State {
B (This option does not allow what A does):
struct Update : public State {
My question is: is this good or bad practice?
----- ----- EDIT:
I do not have access to a compiler that can compile it, however, I was told that "overriding" would be ideal in this situation, for example:
//So states can be "poped in and out".// struct State { //To retrive what the active state is called.// /*Code In Question--->*/virtual std::string RegardStateAs() = 0;/*<---Code In Question*/ virtual void ExecuteState( VRGE::MDNode* metaData ) = 0; }; struct Update : public State { //Yadda yadda...// /*Code In Question--->*/std::string RegardStateAs() override { return std::string{ "Update" }; }/*<---Code In Question*/ };
source share