mardi 24 mars 2015

C++ separation data and logic

The reason why I want to separate in such way - data depends from nothing, methods can have hundred dependencies. All, who depends from data shouldn`t depends from methods dependencies.


I want to do something like:



//s_class_name.h
struct structName
{
data m_data
}





//class_name.h
class className : public structName
{
public:
void method(arg1, arg2, arg3, ..., argN); //using m_data
}





static_cast<className *>(&structNameObject)->method(arg1, arg2, arg3, ..., argN);


There are I see two problems:


1) All acces to data is opened. I want to open data to all, who operate with struct, but not with class.


2) Static cast downcasting is undefined.


Could you explain me, how to realize pattern data&logic separation better?


Aucun commentaire:

Enregistrer un commentaire