03S Objects Interaction II
03S Objects Interaction II
Objects Interaction
Agenda
Objects Interaction
Constructors
Objects Interaction
Do you remember how to instantiate?
Objects Interaction
Constructors
Invoking a constructor
serves as a request to the
JVM to construct
(instantiate) a brand-new
object
Objects Interaction
Constructors
JVM
Objects Interaction
Default constructor
Objects Interaction
Default constructor
Objects Interaction
Explicit constructors
Objects Interaction
Explicit constructors rules
Objects Interaction
Passing parameters to constructors
Test Class
Class definition
Objects Interaction
Be careful
Objects Interaction
Replacing the Default Parameterless Constructor
Objects Interaction
Overloading Constructors
Constructor 1 signature
Student ( )
Constructor 2 signature
Student ( String )
Constructor 3 signature
Objects Interaction
Constructors reuse
Code duplication
Objects Interaction
Constructors reuse
Objects Interaction
Review: Tic Tac Toe
Layers and packages
Constructors and access modificators
Relation between objects
Data Layer
Which classes
belong to the data
layer?
Objects Interaction
Data layer
Objects Interaction
Board class
Overriding default
constructor
Objects Interaction
Printing user defined objects method
Objects Interaction
toString method
Important, do not
forget it
Objects Interaction
Overriding toString method
Objects Interaction
Overloading
constructors
Objects Interaction
Overriding toString method
Objects Interaction
Player class
Objects Interaction
Overriding toString method
Objects Interaction
How do you know if two user defined objects are
equal?
Objects Interaction
Overriding equals method
equals method allow us to override the default way how two user
defined objects are equals or not
Important, do not
forget it
Objects Interaction
Business logic Layer
Which classes
belong to the
business logic
layer?
Objects Interaction
Business logic layer
Objects Interaction
GameEngine Class
Methods can be
private
Objects Interaction
GameEngine Class
Objects Interaction
TurnController Class
Objects Interaction
TurnController Class
Objects Interaction
MovementHandler Class
Objects Interaction
MovementHandler Class
Objects Interaction
UML Class diagram
Objects Interaction
UML Class diagram
DATA
BUSINESS LAYER
LAYER
UI
LAYER
Objects Interaction
Each layers is represented as a package
• Three layers
– Data
– Business logic
– UI
Objects Interaction
Tic Tac Toe
Objects Interaction
References
Objects Interaction