Home  >  Article  >  Java  >  What are the characteristics of java state pattern

What are the characteristics of java state pattern

王林
王林forward
2023-04-29 14:40:10899browse

1. Features

The state class has the same public method

The state class has an attribute pointing to the entity class that uses this state

State The class automatically switches states internally, and the user cannot perceive it

Used to replace large blocks of repeated if statements

2, examples

package com.journaldev.design.state;
 
public class TVStartState implements State {
 
@Override
public void doAction() {
System.out.println("TV is turned ON");
}
 
}

Java has Which collection classes

Collections in Java are mainly divided into four categories:

1. List: ordered and repeatable;

2.Queue: Yes Ordered, repeatable;

3. Set collection: non-repeatable;

4. Map mapping: unordered, with unique keys and non-unique values.

The above is the detailed content of What are the characteristics of java state pattern. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete