Design Pattern Examples
Overview of object-oriented design patterns
NullObject_MoveCommand.c
Go to the documentation of this file.
1
6
7#include <stdlib.h>
8#include <stdio.h>
9
11
13// MoveCommand_Create()
15MoveCommand* MoveCommand_Create(char commandToken, const char* commandName, ExecuteFunction executeFunction)
16{
17 MoveCommand* moveCommand = NULL;
18
19 if (commandName != NULL && executeFunction != NULL)
20 {
21 moveCommand = calloc(1, sizeof(MoveCommand));
22 if (moveCommand != NULL)
23 {
24 moveCommand->commandToken = commandToken;
25 moveCommand->commandName = commandName;
26 moveCommand->Execute = executeFunction;
27 }
28 }
29
30 return moveCommand;
31}
32
34// MoveCommand_Destroy()
37{
38 if (moveCommand != NULL)
39 {
40 moveCommand->commandToken = 0;
41 moveCommand->commandName = NULL;
42 moveCommand->Execute = NULL;
43 free(moveCommand);
44 }
45}
void MoveCommand_Destroy(MoveCommand *moveCommand)
Destroy the specified MoveCommand object. After this function returns, the pointer to the MoveCommand...
MoveCommand * MoveCommand_Create(char commandToken, const char *commandName, ExecuteFunction executeFunction)
Create a MoveCommand object and initialize it with the given arguments.
Declaration of the MoveCommand structure along with the support functions, MoveCommand_Create() and M...
void(* ExecuteFunction)(void)
Alias for a function that executes a move command.
Represents a move command. A move command has a name and the command character that represents the co...
char commandToken
The character that represents this move command in a string.
const char * commandName
The name of this move command.
ExecuteFunction Execute
The function to call to execute the move command (this varies for each command)