
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
55 lines
915 B
Plaintext
55 lines
915 B
Plaintext
== Why is this an issue?
|
|
|
|
By implementing class interfaces with member functions, the implementation retains more control over how the object state can be modified, and helps to allow a class to be maintained without affecting clients.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
class C
|
|
{
|
|
public:
|
|
int32_t b; // Noncompliant
|
|
protected:
|
|
int32_t c; // Noncompliant
|
|
private:
|
|
int32_t d; // Compliant
|
|
};
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
class C
|
|
{
|
|
public:
|
|
int32_t getB() { return _b; }
|
|
void setB(int32_t b) { _b = b; }
|
|
protected:
|
|
int32_t getC() { return _c; }
|
|
void setC(int32_t c) { _c = c; }
|
|
private:
|
|
int32_t _b; // Compliant
|
|
int32_t _c; // Compliant
|
|
int32_t _d; // Compliant
|
|
};
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* MISRA {cpp}:2008, 11-0-1
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== duplicates: S3656
|
|
|
|
endif::env-github,rspecator-view[]
|