![]() |
От: |
velkin
|
https://kisa.biz |
Дата: | 21.10.21 12:05 | ||
Оценка: |
72 (1)
+1
-5
![]() |
C++ — ужасный объектно-ориентированный язык. Ограничение вашего проекта до C означает, что люди не напортачат ни с какой идиотской «объектной моделью».
Линус Торвальдс, создатель Linux
...
Методы или свойства, которые обеспечивают доступ к определённым полям, не лучше, чем непосредственное изменение значения поля. Не имеет значения, изменяете ли вы состояние объекта с помощью необычного свойства или метода, результат один и тот же — изменённое состояние.
...
Падение четырёх столпов:
1) Абстракция.
2) Наследование.
3) Инкапсуляция.
4) Полиморфизм.
В классической теории, модель данных это формальная теория представления и обработки данных.
// структура прямоугольника
template <typename TValue>
struct SRectangle
{
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
};
// класс прямоугольника
template <typename TValue>
class CRectangle
{
public:
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
};
void print_srectangle(const SRectangle<double>& srectangle)
{
qDebug() << "x = " << srectangle.x
<< "y = " << srectangle.y
<< "width = " << srectangle.width
<< "height = " << srectangle.height;
}
void print_crectangle(const CRectangle<double>& crectangle)
{
qDebug() << "x = " << crectangle.x
<< "y = " << crectangle.y
<< "width = " << crectangle.width
<< "height = " << crectangle.height;
}
void using_rectangle()
{
SRectangle<double> srectangle;
CRectangle<double> crectangle;
print_srectangle(srectangle);
print_crectangle(crectangle);
}
/*
Вывод using_rectangle:
x = 0 y = 0 width = 0 height = 0
x = 0 y = 0 width = 0 height = 0
*/
// класс прямоугольника
template <typename TValue>
class CRectangle
{
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
};
void print_crectangle(const CRectangle<double>& crectangle)
{
qDebug() << "x = " << crectangle.x // ошибка: 'x' is a private member of 'CRectangle<double>'
<< "y = " << crectangle.y // ошибка: 'y' is a private member of 'CRectangle<double>'
<< "width = " << crectangle.width // ошибка: 'width' is a private member of 'CRectangle<double>'
<< "height = " << crectangle.height; // ошибка: 'height' is a private member of 'CRectangle<double>'
}
Инкапсуляция (англ. encapsulation, от лат. in capsula) — в информатике размещение в одном компоненте данных и методов, которые с ними работают. В реализации большинства языков программирования (C++, C#, Java и другие), обеспечивает механизм сокрытия, позволяющий разграничивать доступ к различным компонентам программы.
// структура прямоугольника
template <typename TValue>
struct SRectangle
{
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
};
// класс прямоугольника
template <typename TValue>
class CRectangle
{
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
public:
inline const TValue& get_x() const { return x; }
inline const TValue& get_y() const { return y; }
inline const TValue& get_width() const { return width; }
inline const TValue& get_height() const { return height; }
inline void set_x(const TValue& x) { this->x = x; }
inline void set_y(const TValue& y) { this->y = y; }
inline void set_width(const TValue& width) { this->width = width; }
inline void set_height(const TValue& height) { this->height = height; }
};
void print_srectangle(const SRectangle<double>& srectangle)
{
qDebug() << "x = " << srectangle.x
<< "y = " << srectangle.y
<< "width = " << srectangle.width
<< "height = " << srectangle.height;
}
void print_crectangle(const CRectangle<double>& crectangle)
{
qDebug() << "x = " << crectangle.get_x()
<< "y = " << crectangle.get_y()
<< "width = " << crectangle.get_width()
<< "height = " << crectangle.get_height();
}
void using_rectangle()
{
SRectangle<double> srectangle;
CRectangle<double> crectangle;
print_srectangle(srectangle);
print_crectangle(crectangle);
srectangle.x = 1;
srectangle.y = 2;
srectangle.width = 3;
srectangle.height = 4;
print_srectangle(srectangle);
crectangle.set_x(5);
crectangle.set_y(6);
crectangle.set_width(7);
crectangle.set_height(8);
print_crectangle(crectangle);
}
/*
Вывод using_rectangle:
x = 0 y = 0 width = 0 height = 0
x = 0 y = 0 width = 0 height = 0
x = 1 y = 2 width = 3 height = 4
x = 5 y = 6 width = 7 height = 8
*/
// площадь прямоугольника
template <typename TValue>
TValue rectangle_area(const TValue& width, const TValue& height)
{
return width * height;
}
void using_rectangle()
{
SRectangle<double> srectangle;
CRectangle<double> crectangle;
print_srectangle(srectangle);
print_crectangle(crectangle);
srectangle.x = 1;
srectangle.y = 2;
srectangle.width = 3;
srectangle.height = 4;
print_srectangle(srectangle);
crectangle.set_x(5);
crectangle.set_y(6);
crectangle.set_width(7);
crectangle.set_height(8);
print_crectangle(crectangle);
qDebug() << "srectangle_area = " << rectangle_area(
srectangle.width, srectangle.height);
qDebug() << "crectangle_area = " << rectangle_area(
crectangle.get_width(), crectangle.get_height());
}
/*
Вывод using_rectangle:
x = 0 y = 0 width = 0 height = 0
x = 0 y = 0 width = 0 height = 0
x = 1 y = 2 width = 3 height = 4
x = 5 y = 6 width = 7 height = 8
srectangle_area = 12
crectangle_area = 56
*/
// структура прямоугольника
template <typename TValue>
struct SRectangle
{
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
};
// класс прямоугольника
template <typename TValue>
class CRectangle
{
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
public:
inline const TValue& get_x() const { return x; }
inline const TValue& get_y() const { return y; }
inline const TValue& get_width() const { return width; }
inline const TValue& get_height() const { return height; }
inline void set_x(const TValue& x) { this->x = x; }
inline void set_y(const TValue& y) { this->y = y; }
inline void set_width(const TValue& width) { this->width = width; }
inline void set_height(const TValue& height) { this->height = height; }
TValue rectangle_area() const { return width * height; }
};
void print_srectangle(const SRectangle<double>& srectangle)
{
qDebug() << "x = " << srectangle.x
<< "y = " << srectangle.y
<< "width = " << srectangle.width
<< "height = " << srectangle.height;
}
void print_crectangle(const CRectangle<double>& crectangle)
{
qDebug() << "x = " << crectangle.get_x()
<< "y = " << crectangle.get_y()
<< "width = " << crectangle.get_width()
<< "height = " << crectangle.get_height();
}
// площадь прямоугольника
template <typename TValue>
TValue rectangle_area(const TValue& width, const TValue& height)
{
return width * height;
}
void using_rectangle()
{
SRectangle<double> srectangle;
CRectangle<double> crectangle;
print_srectangle(srectangle);
print_crectangle(crectangle);
srectangle.x = 1;
srectangle.y = 2;
srectangle.width = 3;
srectangle.height = 4;
print_srectangle(srectangle);
crectangle.set_x(5);
crectangle.set_y(6);
crectangle.set_width(7);
crectangle.set_height(8);
print_crectangle(crectangle);
qDebug() << "srectangle_area = " << rectangle_area(
srectangle.width, srectangle.height);
qDebug() << "crectangle_area = " << crectangle.rectangle_area();
}
/*
Вывод using_rectangle:
x = 0 y = 0 width = 0 height = 0
x = 0 y = 0 width = 0 height = 0
x = 1 y = 2 width = 3 height = 4
x = 5 y = 6 width = 7 height = 8
srectangle_area = 12
crectangle_area = 56
*/
// площадь прямоугольника
template <typename TValue>
TValue rectangle_area(const TValue& width, const TValue& height)
{
return width * height;
}
// что-то там
template <typename TValue>
TValue something_there(const TValue& some_value, const TValue& another_value)
{
return some_value * another_value;
}
class CRectangle
{
// начало блока описывающего внутреннее состояние класса
TValue x = 0;
TValue y = 0;
TValue width = 0;
TValue height = 0;
// конец блока описывающего внутреннее состояние класса
public:
inline const TValue& get_x() const { return x; }
inline const TValue& get_y() const { return y; }
inline const TValue& get_width() const { return width; }
inline const TValue& get_height() const { return height; }
inline void set_x(const TValue& x) { this->x = x; }
inline void set_y(const TValue& y) { this->y = y; }
inline void set_width(const TValue& width) { this->width = width; }
inline void set_height(const TValue& height) { this->height = height; }
// использование внутреннего состояния класса вне свойств
TValue rectangle_area() { return width * height; }
};
// структура двухмерной координаты
template <typename TValue>
struct SCartesianPoint2D
{
TValue x = 0;
TValue y = 0;
};
// структура двухмерного размера
template <typename TValue>
struct SSize2D
{
TValue width = 0;
TValue height = 0;
};
// структура прямоугольника
template <typename TValue>
struct SRectangle
{
SCartesianPoint2D<TValue> cartesian_point2d;
SSize2D<TValue> size2d;
};
// класс двухмерной координаты
template <typename TValue>
class CCartesianPoint2D
{
TValue x = 0;
TValue y = 0;
public:
inline const TValue& get_x() const { return x; }
inline const TValue& get_y() const { return y; }
inline void set_x(const TValue& x) { this->x = x; }
inline void set_y(const TValue& y) { this->y = y; }
};
// класс двухмерного размера
template <typename TValue>
class CSize2D
{
TValue width = 0;
TValue height = 0;
public:
inline const TValue& get_width() const { return width; }
inline const TValue& get_height() const { return height; }
inline void set_width(const TValue& width) { this->width = width; }
inline void set_height(const TValue& height) { this->height = height; }
// площадь прямоугольника в классе размер
TValue rectangle_area() const { return width * height; }
};
// класс прямоугольника
template <typename TValue>
class CRectangle
{
// начало блока описывающего внутреннее состояние класса
CCartesianPoint2D<TValue> cartesian_point2d;
CSize2D<TValue> size2d;
// конец блока описывающего внутреннее состояние класса
public:
inline const CCartesianPoint2D<TValue>& get_cartesian_point2d() const
{ return cartesian_point2d; }
inline const CSize2D<TValue>& get_size2d() const { return size2d; }
inline void set_cartesian_point2d(const TValue& cartesian_point2d)
{ this->cartesian_point2d = cartesian_point2d; }
inline void set_size2d(const TValue& size2d) { this->size2d = size2d; }
// лишнее делегирование
inline const TValue& get_x() const { return cartesian_point2d.get_x(); }
inline const TValue& get_y() const { return cartesian_point2d.get_y(); }
inline const TValue& get_width() const { return size2d.get_width(); }
inline const TValue& get_height() const { return size2d.get_height(); }
inline void set_x(const TValue& x) { cartesian_point2d.set_x(x); }
inline void set_y(const TValue& y) { cartesian_point2d.set_y(y); }
inline void set_width(const TValue& width) { size2d.set_width(width); }
inline void set_height(const TValue& height) { size2d.set_height(height); }
// площадь прямоугольника в классе прямоугольник
TValue rectangle_area() const { return size2d.get_width() * size2d.get_height(); }
};
void print_srectangle(const SRectangle<double>& srectangle)
{
qDebug() << "x = " << srectangle.cartesian_point2d.x
<< "y = " << srectangle.cartesian_point2d.y
<< "width = " << srectangle.size2d.width
<< "height = " << srectangle.size2d.height;
}
void print_crectangle(const CRectangle<double>& crectangle)
{
qDebug() << "x = " << crectangle.get_x()
<< "y = " << crectangle.get_y()
<< "width = " << crectangle.get_width()
<< "height = " << crectangle.get_height();
}
// площадь прямоугольника
template <typename TValue>
TValue rectangle_area(const TValue& width, const TValue& height)
{
return width * height;
}
// что-то там
template <typename TValue>
TValue something_there(const TValue& some_value, const TValue& another_value)
{
return some_value * another_value;
}
void using_rectangle()
{
SRectangle<double> srectangle;
CRectangle<double> crectangle;
print_srectangle(srectangle);
print_crectangle(crectangle);
srectangle.cartesian_point2d.x = 1;
srectangle.cartesian_point2d.y = 2;
srectangle.size2d.width = 3;
srectangle.size2d.height = 4;
print_srectangle(srectangle);
crectangle.set_x(5);
crectangle.set_y(6);
crectangle.set_width(7);
crectangle.set_height(8);
print_crectangle(crectangle);
qDebug() << "srectangle_area = " << rectangle_area(
srectangle.size2d.width, srectangle.size2d.height);
qDebug() << "crectangle_area = " << crectangle.rectangle_area();
qDebug() << "crectangle_area = " << crectangle.get_size2d().rectangle_area();
}
/*
Вывод using_rectangle:
x = 0 y = 0 width = 0 height = 0
x = 0 y = 0 width = 0 height = 0
x = 1 y = 2 width = 3 height = 4
x = 6 y = 0 width = 7 height = 8
srectangle_area = 12
crectangle_area = 56
crectangle_area = 56
*/
OLAP (англ. online analytical processing, интерактивная аналитическая обработка) — технология обработки данных, заключающаяся в подготовке суммарной (агрегированной) информации на основе больших массивов данных, структурированных по многомерному принципу.
OLAP-куб — (On-Line Analytical Processing — интерактивный анализ данных) многомерный массив данных, как правило, разреженный и долговременно хранимый, используемый в OLAP. Может быть реализован на основе универсальных реляционных СУБД или специализированным программным обеспечением.
Тессера́кт (от др.-греч. τέσσαρες ἀκτῖνες — «четыре луча») — четырёхмерный гиперкуб, аналог обычного трёхмерного куба в четырёхмерном пространстве.
Гиперку́б — обобщение куба на случай с произвольным числом измерений.
кол-во элементов | однородные типы | разнородные типы |
---|---|---|
0..1 | ||
0..n | ||
0..∞ | динамический массив | |
1..1 | значение | вариант |
1..n | ||
1..∞ | ||
n..n | статический массив | структура |
n..∞ |
одномерное | двухмерное | трёхмерное | четырёхмерное | ... | n-мерное |
---|---|---|---|---|---|
#..# | |||||
#..# | #..# | ||||
#..# | #..# | #..# | |||
#..# | #..# | #..# | #..# | ||
#..# | #..# | #..# | #..# | #..# | |
#..# | #..# | #..# | #..# | #..# | #..# |