Fundamentals 7 min read

Evolution of Software Development, OOP, and Functional Refactoring with Java Predicates

The article traces the three historical stages of software development, explains object‑oriented programming fundamentals, highlights the duplication problem in traditional query methods, and demonstrates how Java 8 functional programming with Predicate interfaces can refactor and compose flexible query logic.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Evolution of Software Development, OOP, and Functional Refactoring with Java Predicates

The development of software can be divided into three historical stages: the early scientific‑engineering computing era (mid‑1940s to mid‑1950s), the period of high‑level languages and emerging software engineering (mid‑1950s to late‑1960s), and the modern software‑engineering era (late‑1960s onward) where large projects require collaborative management.

Object‑oriented programming (OOP) is introduced as a paradigm that encapsulates data and behavior into objects, featuring encapsulation, inheritance, and polymorphism. An example Activity class illustrates typical fields such as id, name, desc, time, and publisher:

/**
 * @Author onlyone
 * <p>
 * 活动模型
 */
public class Activity {
    private Long id; // 活动id
    private String name; // 名称
    private String desc;  // 描述
    private Date time;  // 活动时间
    private String publisher; // 发布人
}

Traditional query methods iterate over a list and compare each field, leading to duplicated code for each criterion:

public Activity queryById(List<Activity> activityList, String id) {
    for (Activity activity : activityList) {
        if (id.equals(activity.getId())) {
            return activity;
        }
    }
    return null;
}

public Activity queryByName(List<Activity> activityList, String name) {
    for (Activity activity : activityList) {
        if (name.equals(activity.getId())) { // simplified example
            return activity;
        }
    }
    return null;
}

Functional programming is presented as a solution, emphasizing that functions can be created on demand, passed as arguments, and returned as values. Java 8 introduces functional interfaces such as Predicate, Function, Supplier, and Consumer.

@FunctionalInterface
public interface Predicate<T> {
    boolean test(T t);
}

A refactored class uses a generic queryByPredicate method that accepts any Predicate<Activity> to perform the search:

public class FuncitionProgram {
    private List<Activity> activityList;

    /**
     * 基础查询骨架
     */
    Activity queryByPredicate(Predicate<Activity> predicate) {
        for (Activity activity : activityList) {
            if (predicate.test(activity)) {
                return activity;
            }
        }
        return null;
    }
}

Specific queries become one‑line lambda calls:

public Activity queryById(String id) {
    return queryByPredicate(activity -> id.equals(activity.getId()));
}

public Activity queryByName(String name) {
    return queryByPredicate(activity -> name.equals(activity.getName()));
}

To further promote reuse, atomic predicate factories are defined:

// id判断函数
public Predicate<Activity> idPredicate(String id) {
    return activity -> id.equals(activity.getId());
}

// 名称判断函数
public Predicate<Activity> namePredicate(String name) {
    return activity -> name.equals(activity.getName());
}

These predicates can be composed by the caller, enabling flexible combinations such as:

// 按id查询活动
queryByPredicate(idPredicate(id));
// 按名称查询活动
queryByPredicate(namePredicate(name));
// 按id、名称组合条件查询活动
queryByPredicate(idPredicate(id).and(namePredicate(name)));

The article concludes that by abstracting query logic into composable functions, developers gain greater flexibility, reduce code duplication, and align with modern architectural principles for scalable, maintainable systems.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Javasoftware developmentFunctional ProgrammingRefactoringPredicates
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.