admin 发布的文章

如何定义一个设计模式呢?为何不能定义一个新的设计模式呢?难道就只有 GoF 中所说的 23 种设计模式吗?

有感于贾玲的电影《热辣滚烫》,她减肥了100多斤,想到自己曾经 55KG 的标准体重如今也涨到了 62KG 了。既然她是通过拳击减了肥(在电影里),巧了,我 Switch 上也买了有氧拳击2,那不如也试试通过拳击来减肥?

爱因斯坦一生说过很多话。也不知道他在什么时候,什么情况下,说过一句“想象力比知识更重要”,结果中国的儿童教育家们就记住了这一句话。到了郑渊洁这一代,此话已经被推论到:“想象力和知识是天敌。人在获得知识的过程中,想象力会消失。因为知识符合逻辑,而想象力无章可循。换句话说,知识的本质是科学,想象力的特征是荒诞。”

旅游,若无强烈的目的,独自一人则显得孤独,尤其是国内这种千篇一律的景点。除了拍照打卡之外,没有其他功能。
所以,若非有强烈的目的,否则一个人的旅游毫无乐趣。

不起作用

Why does the custom instructions not work?
为什么自定义指令不起作用?

Summary

The Chain of Responsibility pattern is a design pattern used in software development. It's a part of the behavioral design patterns, which are concerned with algorithms and the assignment of responsibilities between objects.

The Factory Pattern is a creational design pattern used in software development. It provides a way to encapsulate object creation without specifying the exact class of object that will be created.
工厂模式是一种用于软件开发的创建设计模式。它提供了一种封装对象创建的方法,而无需指定将要创建的对象的具体类别。

The Decorator Pattern is another fundamental design pattern used in software development, especially useful for adding new functionalities to objects dynamically. It provides a flexible alternative to subclassing for extending functionality.
装饰者模式(Decorator Pattern)是软件开发中使用的另一种基本设计模式,尤其适用于为对象动态添加新功能。它为扩展功能提供了一种灵活的子类化替代方案。

The Observer Pattern is a widely used design pattern in software engineering. It's particularly useful for creating a system where an object (the subject) needs to notify a list of observers about any state changes.
观察者模式是软件工程中广泛使用的一种设计模式。它特别适用于创建一个系统,在这个系统中,一个对象(主体)需要将任何状态变化通知一系列观察者。

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        // Example usage
        int unixTimestamp = 1640995200; // Example Unix timestamp
        String formattedDate = formatUnixTimestamp(unixTimestamp);
        System.out.println(formattedDate);
    }

    public static String formatUnixTimestamp(int unixTimestamp) {
        // Convert int Unix timestamp to long and then to Instant
        Instant instant = Instant.ofEpochSecond((long) unixTimestamp);

        // Convert Instant to LocalDateTime
        LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

        // Format LocalDateTime to String
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTime.format(formatter);
    }
}

策略模式定义了一个算法族,分别封装起来,使得它们之间可以互相变换。策略让算法的变化独立于使用它的客户。

编程语言不过是一种内存游戏,定义的变量也好,对象也好,都只是在内存中的特定编码。其实根本就没什么语言,有的只是编译器。是编译器决定怎么解释某种关键字及某种语法。语言只是编译器和大家的约定,只要写入这样的代码,编译器便将其翻译成某种机器指令,翻译成什么样取决于编译器的行为,和语言无关。