I think this is a common style, and this is definitely one of the main motives for getter / seters in the first idea. However, in your specific example, I donβt think they make sense, and I think that in general there are often better alternatives:
GetGroupID , HasGroupID false, , , , assert. , ? .
, , , . , , , , ( , !), - . :
class GroupID {
public:
explicit GroupID( int id ) : m_id( id ) {
if ( m_id == 0 ) {
throw EPTBadArgumentException( "GroupID must not be zero!", m_id );
}
}
operator int() const { return m_id; }
};
,
void MyClass::SetGroupID( GroupID id )
{
m_iGroupID = id;
}
, , Set . , MyClass::Set(UserID) MyClass::Set(GroupID) ..