Java Design Patterns

c82-java-prog-logo

Advanced Class

Design Pattern
Singleton
Factory
Builder
Deps Injection
Scale is large enough (then need Design Pattern)
Project Requirement
Epic Fantasy Story
Role Play Game (RPG)
Turn-based Strategy fighting system
Treasure Collection
Players
Pick Roles
NPC Roles
Analysis
Ability promotion
inner class
Builder
build()
too many parameters / integers / optional parameters, no context for parameters
Google Protobuf / Google AutoValue
immutable / mutable
Map (World)
X * Y grid
Each world[x][y] is a block
Block could be free path or obstacle
Block can trigger events
Events can fight or collect treasure
Multiple players are walking in the world
Singleton
if (instance == null) {
  synchronized(this) {
    if (instance == null) {
      instance = new World();
    }
  }
}
World (Block as shop, path, fight, obstacle)
Factory
Hide initialization from clients (low coupling)
Make a hub for registering and create new instances (high cohesion)
Dependency Injection
Service maintains the initialization dependencies
Client doesn’t need to know about that
Normally, service is provided by framework
Google Guide, Spring, AngularJS
Interactions
Controller
Gather models manipulations (controller -> world, player, battlefield)
Simplify models
Users interface will be simpler
Low coupling
Summary
Builder
– ProtoBuf
– AutoValue
Singleton
– Thread safe
Factory
– High Cohesion, low coupling
Deps Injection
Controller
Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Resources:

Core Java Volume I–Fundamentals (10th Edition) (Core Series)

Core Java, Volume II–Advanced Features (10th Edition) (Core Series)

Test-Driven Java Development

Java Concurrency in Practice

Java: An Introduction to Problem Solving and Programming (7th Edition)

Java 9 for Programmers (Deitel Developer Series)

Java SE8 for the Really Impatient: A Short Course on the Basics (Java Series)

Core Java for the Impatient

Java: The Beginners Guide for every non-programmer which will attend you trough your learning process

Java Deep Learning Essentials

Machine Learning in Java

Learning Reactive Programming With Java 8

Java 9 Programming By Example

Thinking in Java (4th Edition)

The Java EE Architect’s Handbook, Second Edition: How to be a successful application architect for Java EE applications

Java Artificial Intelligence: Made Easy, w/ Java Programming

Advertisements

About liyao13

Yao Li is a web and iOS developer, blogger and he has a passion for technology and business. In his blogs, he shares code snippets, tutorials, resources and notes to help people develop their skills. Donate $5 to him for a coffee with PayPal at About Me page and read more professional and interesting technical blog articles. Follow him @Yaoli0615 at Twitter to get latest tech updates.
This entry was posted in CS Research&Application, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s