"Effective Java"精读之创建和销毁对象

1. 考虑使用构造器代替可变参数的工厂方法 在面对多个构造参数时,工厂方法提供了一种灵活的选择,但若可变参数的数量和类型太多时,会使得代码变得难以...

周六 · 2024-12-28 · 4 分钟 · Yuechen

Design Uber

Implement a Cab Booking Application (like Uber) which facilitates: Addition of new cabs to the system. Updating the trips of various customers. Finding the nearest cabs to a location. Design the Uber class: Uber() Initializes the Uber object with 0 cabs and 0 running trips. void addCab(int cabX, int cabY) Adds a cab located at point (cabX, cabY) to the system. Note that multiple cabs can be at the same...

周六 · 2024-12-28 · 5 分钟 · Yuechen

Encode and Decode TinyURL

TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL....

周六 · 2024-12-21 · 7 分钟 · Yuechen

Design Twitter

Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user’s news feed. Implement the Twitter class: Twitter() Initializes your twitter object. void postTweet(int userId, int tweetId) Composes a new tweet with ID tweetId by the user userId. Each call to this function will be made with a unique tweetId. List<Integer> getNewsFeed(int userId) Retrieves...

周六 · 2024-12-14 · 4 分钟 · Yuechen

面向切面编程 (AOP)

AOP(Aspect-Oriented Programming,面向切面编程) 是 Java 和 Spring 中的重要概念,它通过将横切关注点从业务逻辑中分离,使代码...

周日 · 2024-12-08 · 7 分钟 · Yuechen

Design a Dating System

Design a simple dating system like Tinder with the following features: Register a user with their gender, age, preferences, and interests. Find matching users according to their preferred gender, preferred age range, and common interests. Implement the Tinder class: Tinder() Initializes the object. void signup(int userId, int gender, int preferredGender, int age, int minPreferredAge, int maxPreferredAge, List<String> interests) Registers a user with the given attributes. List<Integer> getMatches(int userId) Returns the...

周六 · 2024-12-07 · 3 分钟 · Yuechen

Java 中的注解 (Annotation)

Java 的 注解(Annotation) 是一种用于元编程的工具,它为 Java 程序员提供了一种将元信息嵌入到代码中的方式。通过注解,开发者可以在编译时或运行...

周日 · 2024-12-01 · 6 分钟 · Yuechen

Design Facebook

Design a system like Facebook with the following features: A user can write a post. Two users can become friends with each other. Users can see all the posts written by their friends. Implement the Facebook class: Facebook() Initializes the object. void writePost(int userId, String postContent) The user with id userId writes a post with the content postContent. void addFriend(int user1, int user2) user1 and user2 become friends with each...

周六 · 2024-11-30 · 2 分钟 · Yuechen