SlideShare a Scribd company logo
Chapter 3.3
Programming Fundamentals
2
Data Structures
 Arrays
 Elements are adjacent in memory (great
cache consistency)
 They never grow or get reallocated
 In C++ there's no check for going out of
bounds
 Inserting and deleting elements in the
middle is expensive
3
Data Structures
 Linked lists
 Very cheap to add/remove elements.
 Available in the STL (std::list)
 Every element is allocated separately

Lots of little allocations
 Not placed contiguously in memory
4
Data Structures
 Dictionaries
 Maps a set of keys to some data.
 std::map, std::hash, etc
 Very fast access to data
 Perfect for mapping IDs to pointers, or
resource handles to objects
5
Data Structures
 Stacks
 First in, last out
 std::stack adaptor in STL
 Queues
 First in, first out
 std::deque
6
Data Structures
 Bit packing
 Fold all necessary data into a smaller
number of bits
 Very useful for storing boolean flags

(pack 32 in a double word)
 Possible to apply to numerical values if we
can give up range or accuracy
 Very low level trick

Only use when absolutely necessary
7
Object Oriented Design
 Concepts
 Class

Abstract specification of a data type
 Instance

A region of memory with associated semantics to
store all the data members of a class
 Object

Another name for an instance of a class
8
Object Oriented Design
 Inheritance
 Models “is-a” relationship
 Extends behavior of existing classes by
making minor changes
9
Object Oriented Design
 Inheritance
 UML diagram representing inheritance
E n e m y B o s s S u p e r D u p e r B o s s
10
Object Oriented Design
 Polymorphism
 The ability to refer to an object through a
reference (or pointer) of the type of a parent
class
 Key concept of object oriented design
11
Object Oriented Design
 Multiple Inheritance
 Allows a class to have more than one base
class
 Derived class adopts characteristics of all
parent classes
 Huge potential for problems (clashes,
casting, etc)
 Multiple inheritance of abstract interfaces is
much less error prone
12
Component Systems
 Limitations of inheritance
 Tight coupling
 Unclear flow of control
 Not flexible enough
 Static hierarchy
13
Component Systems
 Component system organization
 Use aggregation (composition) instead of
inheritance
 A game entity can “own” multiple
components that determine its behavior
 Each component can execute whenever the
entity is updated
 Messages can be passed between
components and to other entities
14
Component Systems
 Component system organization
G a m e E n t i t y
N a m e = s w o r d
R e n d e r C o m p C o l l i s i o n C o m p D a m a g e C o m p P i c k u p C o m p W i e l d C o m p
15
Component Systems
 Data-Driven Composition
 The structure of the game entities can be
specified in data
 Components are created and loaded at
runtime
 Very easy to change (which is very
important in game development)
16
Component Systems
 Analysis
 Very hard to debug
 Performance can be a bottleneck
 Keeping code and data synchronized can
be a challenge
 Extremely flexible

Great for experimentation and varied gameplay
 Not very useful if problem/game is very well
known ahead of time
17
Design Patterns
 Singleton
 Implements a single instance of a class with
global point of creation and access
 Don't overuse it!!!
S i n g l e t o n
s t a t ic S in g le t o n & G e t I n s t a n c e ( ) ;
/ / R e g u la r m e m b e r f u n c t io n s . . .
s t a t ic S in g le t o n u n iq u e I n s t a n c e ;
18
Design Patterns
 Object Factory
 Creates objects by name
 Pluggable factory allows for new object
types to be registered at runtime
 Extremely useful in game development for
creating new objects, loading games, or
instantiating new content after game ships
19
Design Patterns
 Object factory
O b j e c t F a c t o r y
P r o d u c t * C r e a t e O b je c t ( P r o d u c t T y p e t y p e ) ;
C r e a t e P r o d u c t
P r o d u c t
20
Design Patterns
 Observer
 Allows objects to be notified of specific
events with minimal coupling to the source
of the event
 Two parts

subject and observer
21
Design Patterns
 Observer
S u b j e c t
A t t a c h ( O b s e r v e r * ) ;
D e t a c h ( O b s e r v e r * ) ;
N o t if y ( ) ;
O b s e r v e r
U p d a t e ( ) ;
C o n c r e t e O b s e r v e r
U p d a t e ( ) ;
C o n c r e t e S u b j e c t
22
Design Patterns
 Composite
 Allow a group of objects to be treated as a
single object
 Very useful for GUI elements, hierarchical
objects, inventory systems, etc
23
Design Patterns
 Composite
C o m p o s i t e
O p e r a t io n ( ) ;
lis t < C o m p o n e n t * > c h ild r e n
S p e c i f i c C o m p o n e n t
O p e r a t io n ( ) ;
C o m p o n e n t
O p e r a t io n ( ) ;

More Related Content

PPTX
Intro to object oriented programming
PPS
Introduction to CSharp
PPT
Introduction To Csharp
PPT
Introduction to csharp
PDF
Introduction To Csharp
PPT
Introduction to csharp
PPT
Introduction to csharp
PPTX
Data oriented design
Intro to object oriented programming
Introduction to CSharp
Introduction To Csharp
Introduction to csharp
Introduction To Csharp
Introduction to csharp
Introduction to csharp
Data oriented design

What's hot (16)

PPTX
A well-typed program never goes wrong
PPTX
C++ Constructor destructor
PDF
Writing Node.js Bindings - General Principles - Gabriel Schulhof
PPTX
Concept of constructors
PPSX
Constructor and destructor
PPT
Constructor & Destructor
PPTX
PDF
04. constructor & destructor
PDF
Eugene Burmako
PPTX
PPT
Structure in c
PPT
C++lecture9
PDF
Semmle Codeql
PDF
Jvmls 2019 feedback valhalla update
PPT
Tutconstructordes
A well-typed program never goes wrong
C++ Constructor destructor
Writing Node.js Bindings - General Principles - Gabriel Schulhof
Concept of constructors
Constructor and destructor
Constructor & Destructor
04. constructor & destructor
Eugene Burmako
Structure in c
C++lecture9
Semmle Codeql
Jvmls 2019 feedback valhalla update
Tutconstructordes
Ad

Similar to 3.3 programming fundamentals (20)

PPTX
Architecture and design
POTX
JDD2015: Twenty-one years of "Design Patterns" - Ralph Johnson
PDF
Style & Design Principles 02 - Design Patterns
PPT
M04_DesignPatterns software engineering.ppt
PPTX
L05 Design Patterns
DOCX
Design patterns
PDF
software engineering Design Patterns.pdf
PPT
Design Patterns
PPTX
Software System Architecture-Lecture 6.pptx
PPT
Design pattern
PDF
Design patterns for fun & profit - CoderCruise 2018
PPTX
Building blocks (Game Architecture)
PDF
Design Patterns Java programming language.pdf
PPTX
PATTERNS01 - An Introduction to Design Patterns
PPTX
Design patterns
PDF
08. Design Patterns
PPT
lecture10-patterns.ppt
PPT
lecture10-patterns.ppt
PPTX
L03 Design Patterns
PPTX
ap assignmnet presentation.pptx
Architecture and design
JDD2015: Twenty-one years of "Design Patterns" - Ralph Johnson
Style & Design Principles 02 - Design Patterns
M04_DesignPatterns software engineering.ppt
L05 Design Patterns
Design patterns
software engineering Design Patterns.pdf
Design Patterns
Software System Architecture-Lecture 6.pptx
Design pattern
Design patterns for fun & profit - CoderCruise 2018
Building blocks (Game Architecture)
Design Patterns Java programming language.pdf
PATTERNS01 - An Introduction to Design Patterns
Design patterns
08. Design Patterns
lecture10-patterns.ppt
lecture10-patterns.ppt
L03 Design Patterns
ap assignmnet presentation.pptx
Ad

More from Sayed Ahmed (20)

PDF
Workplace, Data Analytics, and Ethics
PPTX
Python py charm anaconda jupyter installation and basic commands
PPTX
[not edited] Demo on mobile app development using ionic framework
PPTX
Sap hana-ide-overview-nodev
PPTX
Invest wisely
PPTX
Will be an introduction to
PPTX
Whm and cpanel overview hosting control panel overview
PPTX
Web application development using zend framework
PPTX
Web design and_html_part_3
PPTX
Web design and_html_part_2
PPTX
Web design and_html
PPTX
Visual studio ide shortcuts
PPTX
Virtualization
PPT
User interfaces
PPT
Unreal
PPTX
Unit tests in_symfony
PPTX
Telerik this is sayed
PPTX
System analysis and_design
PPTX
Symfony 2
PPT
Story telling and_narrative
Workplace, Data Analytics, and Ethics
Python py charm anaconda jupyter installation and basic commands
[not edited] Demo on mobile app development using ionic framework
Sap hana-ide-overview-nodev
Invest wisely
Will be an introduction to
Whm and cpanel overview hosting control panel overview
Web application development using zend framework
Web design and_html_part_3
Web design and_html_part_2
Web design and_html
Visual studio ide shortcuts
Virtualization
User interfaces
Unreal
Unit tests in_symfony
Telerik this is sayed
System analysis and_design
Symfony 2
Story telling and_narrative

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
MIND Revenue Release Quarter 2 2025 Press Release
The Rise and Fall of 3GPP – Time for a Sabbatical?
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

3.3 programming fundamentals

  • 2. 2 Data Structures  Arrays  Elements are adjacent in memory (great cache consistency)  They never grow or get reallocated  In C++ there's no check for going out of bounds  Inserting and deleting elements in the middle is expensive
  • 3. 3 Data Structures  Linked lists  Very cheap to add/remove elements.  Available in the STL (std::list)  Every element is allocated separately  Lots of little allocations  Not placed contiguously in memory
  • 4. 4 Data Structures  Dictionaries  Maps a set of keys to some data.  std::map, std::hash, etc  Very fast access to data  Perfect for mapping IDs to pointers, or resource handles to objects
  • 5. 5 Data Structures  Stacks  First in, last out  std::stack adaptor in STL  Queues  First in, first out  std::deque
  • 6. 6 Data Structures  Bit packing  Fold all necessary data into a smaller number of bits  Very useful for storing boolean flags  (pack 32 in a double word)  Possible to apply to numerical values if we can give up range or accuracy  Very low level trick  Only use when absolutely necessary
  • 7. 7 Object Oriented Design  Concepts  Class  Abstract specification of a data type  Instance  A region of memory with associated semantics to store all the data members of a class  Object  Another name for an instance of a class
  • 8. 8 Object Oriented Design  Inheritance  Models “is-a” relationship  Extends behavior of existing classes by making minor changes
  • 9. 9 Object Oriented Design  Inheritance  UML diagram representing inheritance E n e m y B o s s S u p e r D u p e r B o s s
  • 10. 10 Object Oriented Design  Polymorphism  The ability to refer to an object through a reference (or pointer) of the type of a parent class  Key concept of object oriented design
  • 11. 11 Object Oriented Design  Multiple Inheritance  Allows a class to have more than one base class  Derived class adopts characteristics of all parent classes  Huge potential for problems (clashes, casting, etc)  Multiple inheritance of abstract interfaces is much less error prone
  • 12. 12 Component Systems  Limitations of inheritance  Tight coupling  Unclear flow of control  Not flexible enough  Static hierarchy
  • 13. 13 Component Systems  Component system organization  Use aggregation (composition) instead of inheritance  A game entity can “own” multiple components that determine its behavior  Each component can execute whenever the entity is updated  Messages can be passed between components and to other entities
  • 14. 14 Component Systems  Component system organization G a m e E n t i t y N a m e = s w o r d R e n d e r C o m p C o l l i s i o n C o m p D a m a g e C o m p P i c k u p C o m p W i e l d C o m p
  • 15. 15 Component Systems  Data-Driven Composition  The structure of the game entities can be specified in data  Components are created and loaded at runtime  Very easy to change (which is very important in game development)
  • 16. 16 Component Systems  Analysis  Very hard to debug  Performance can be a bottleneck  Keeping code and data synchronized can be a challenge  Extremely flexible  Great for experimentation and varied gameplay  Not very useful if problem/game is very well known ahead of time
  • 17. 17 Design Patterns  Singleton  Implements a single instance of a class with global point of creation and access  Don't overuse it!!! S i n g l e t o n s t a t ic S in g le t o n & G e t I n s t a n c e ( ) ; / / R e g u la r m e m b e r f u n c t io n s . . . s t a t ic S in g le t o n u n iq u e I n s t a n c e ;
  • 18. 18 Design Patterns  Object Factory  Creates objects by name  Pluggable factory allows for new object types to be registered at runtime  Extremely useful in game development for creating new objects, loading games, or instantiating new content after game ships
  • 19. 19 Design Patterns  Object factory O b j e c t F a c t o r y P r o d u c t * C r e a t e O b je c t ( P r o d u c t T y p e t y p e ) ; C r e a t e P r o d u c t P r o d u c t
  • 20. 20 Design Patterns  Observer  Allows objects to be notified of specific events with minimal coupling to the source of the event  Two parts  subject and observer
  • 21. 21 Design Patterns  Observer S u b j e c t A t t a c h ( O b s e r v e r * ) ; D e t a c h ( O b s e r v e r * ) ; N o t if y ( ) ; O b s e r v e r U p d a t e ( ) ; C o n c r e t e O b s e r v e r U p d a t e ( ) ; C o n c r e t e S u b j e c t
  • 22. 22 Design Patterns  Composite  Allow a group of objects to be treated as a single object  Very useful for GUI elements, hierarchical objects, inventory systems, etc
  • 23. 23 Design Patterns  Composite C o m p o s i t e O p e r a t io n ( ) ; lis t < C o m p o n e n t * > c h ild r e n S p e c i f i c C o m p o n e n t O p e r a t io n ( ) ; C o m p o n e n t O p e r a t io n ( ) ;