Embedded Concepts Flashcards

1
Q

RAII

A

Resource Acquisition Is Initialization.
Resource acquired in constructor, released in destructor.
Ex: unique_ptr, shared_ptr, scoped_lock, open file in constructor, close in destructor.
Items constructed on the stack or items with auto-lifetime management (smart pointers etc..)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

RAII addresses which aspect of C++?

A

Exceptions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Dependency Injection

A

Inject via constructor arguments the resources a class depends on.
So the creator of Foo managed the creation and insertion of Foo’s dependencies.
Allows easy mocking, testing etc…
Factory Method works with this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

TDD

A

Test Driven Development.

  1. Write a test case - fails to compile with no source.
  2. fill out basic source to compile, but still fails.
  3. fill out basic implementation to pass.
  4. refactor to best implementation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Singleton Pattern C++ Implementation

A
class S
{
public:
// public getter returning single static instance
  static S& getinstance()
  {
    static S instance;
    return S;
  }
private:
// private constructor, copy constructor & assignment
  S(){}
  S(S const&);
  void operator=(S const&);
public:
// public deleted functions (good style)
  s(S const&) = delete;
  void operator=(S const&) = delete;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Singleton Pattern

A

Single instance in system.
Hide constructor so only accessible by itself.
Static (globally accessible) method to get instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Adapter Pattern

A
Make class/interface compatible with another class or interface.
Adapter class can own adaptee class and make calls.
ex: Lm75Ctrl and Lm75CtrlAdapter - just extends the interface of Lm75Ctrl to implement ITempSensor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Factory Method/Abstract Factory Pattern

A

Class or code doesn’t need to know HOW to create objects - or even what kind it will get.
Just calls factory::create_x().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly