english-everyday
== write & share ==

Programming Principles for Frontend Developers

September 20, 2025

Programming Principles for Frontend Developers


Understanding and applying programming principles is crucial for building maintainable, scalable, and clean code. In this article, we’ll explore five essential principles that every frontend developer should master, with practical examples from real-world ecommerce projects.

1. SOLID Principles

Question: Please explain the SOLID principles and how you apply them in frontend projects, especially with React

Answer:

SOLID is a set of 5 object-oriented programming principles that help make code easy to read, maintain, and extend:

  • S (Single Responsibility Principle): Each component/class should have only one reason to change. In React, I make sure each component handles only one function. For example: ProductCard only shows product information, it doesn’t handle cart logic.

  • O (Open-Closed Principle): Components should be open for extension, closed for modification. I use composition (like props, children) to reuse components without changing the original code. For example: create a Button component with a variant prop to support different button styles (primary, secondary).

  • L (Liskov Substitution Principle): Child components can replace parent components without breaking the app. For example, I design the ProductList component to accept any ProductCard, as long as they follow the same interface (props).

  • I (Interface Segregation Principle): Only provide the props that components need. For example, CartItem only receives props like name, price, not the whole product object.

  • D (Dependency Inversion Principle): Use dependency injection to reduce dependencies. In React, I use Context API or DI to pass services (like API client) into components instead of hard-coding them.

Applied in ecommerce: In an ecommerce project, I apply SOLID to organize clean code. For example: separate ProductList (shows product list), ProductFilter (handles filters), and ProductAPI (fetches data) to make it easy to maintain and extend when adding features like price filters.


2. DRY Principle

Question: How do you ensure your code follows the DRY principle in a large ecommerce project?

Answer:

DRY (Don’t Repeat Yourself) ensures we don’t repeat logic/code, helping reduce errors and making it easier to maintain. In large ecommerce projects:

  • Custom hooks: I use custom hooks to reuse logic. For example: create useProductFetch to fetch and cache product data, used by many components like ProductList and ProductDetail.

  • Reusable components: Design components like Button, Card, or FormInput with flexible props to use in many places (for example: “Add to Cart” and “Buy Now” buttons use the same Button component).

  • Utils/helpers: Move common logic (like format price, calculate tax) into functions in utils/price.js, called from many places.

  • CSS modules/Tailwind: Use Tailwind classes or CSS modules to avoid repeating styles, ensuring consistent UI.

Real example: In one project, I noticed form validation logic appeared in both payment form and registration form. I moved it into a useFormValidation hook, reducing code repetition and making it easy to update validation logic later.


3. KISS Principle

Question: In an ecommerce application, how would you apply the KISS principle when designing components?

Answer:

KISS (Keep It Simple Stupid) emphasizes keeping code simple and easy to understand. In ecommerce applications:

  • Simple component design: Each component does only one thing. For example, ProductCard only shows product information (image, name, price), it doesn’t handle cart logic or filters.

  • Avoid complex logic: Instead of putting complex logic inside components, I move it to custom hooks or services. For example, discount calculation logic is moved to utils/calculateDiscount.js.

  • Clear props: Only pass necessary props. For example: ProductCard only receives name, price, image, not the whole product object.

  • Simplified UI: Use UI libraries (like Ant Design) or Tailwind to create consistent interfaces without writing complex CSS.

Real example: When designing CartSummary (cart overview), I keep the component only showing total price and checkout button, while the total calculation logic is handled in the useCart hook for easy debugging and reuse.


4. YAGNI Principle

Question: Please give an example of when you violated a programming principle (like YAGNI) and how you fixed it

Answer:

YAGNI (You Aren’t Gonna Need It) requires writing only necessary code, avoiding implementing features that aren’t needed yet. In a previous ecommerce project, I violated YAGNI when I added a complex product filter system (by color, size, brand) from the start, even though the initial requirement only needed category filtering. This increased development time and made the codebase more complex.

How I fixed it:

  • I refactored the code, removed unnecessary filters, kept only category filtering.
  • Moved filter logic into a custom hook (useProductFilter) for easy extension later.
  • Worked with the team to identify real requirements, only adding new filters when customers requested them.

Result: Reduced feature development time by 30% and made the codebase easier to maintain. When customers later requested color filtering, I could easily extend it thanks to the modular design.


5. Maintainability and Scalability

Question: How do you ensure maintainability and scalability in an ecommerce website’s codebase?

Answer:

To ensure maintainable and scalable codebase in ecommerce:

  • Clear folder structure: Organize by features, for example: components/Product, hooks/product, utils/api. This makes it easy to find and add new features.

  • Code reuse: Use custom hooks, reusable components, and utilities to avoid code repetition. For example, useCart hook handles cart logic for both mobile and desktop.

  • TypeScript: Use TypeScript to define types/interfaces, ensuring type safety and easy refactoring, especially when integrating complex APIs (like product lists, cart).

  • Document code: Write comments or README for important components/hooks, for example: clearly explain how to use ProductList component and its props.

  • Code review and linter: Apply ESLint, Prettier to ensure consistent code style, and perform code reviews to catch issues early.

  • Performance optimization: Use lazy loading, code splitting (in Next.js), and caching (React Query) to ensure the app runs smoothly when scaling to high traffic (like flash sales).

Real example: In one project, I organized the codebase by features (like cart/, product/), used TypeScript to define types for API responses, and integrated React Query to cache product data. This helped the team easily add new payment features without breaking other parts.


Conclusion

These programming principles are not just theoretical concepts—they’re practical tools that help you write better code. By applying SOLID, DRY, KISS, YAGNI, and focusing on maintainability, you can build frontend applications that are:

  • Easier to maintain and debug
  • More scalable as your team and requirements grow
  • Less prone to bugs and errors
  • Faster to develop new features
  • More enjoyable to work with

Remember, the goal isn’t to follow these principles rigidly, but to use them as guidelines to make better decisions in your code. Start small, apply them gradually, and you’ll see the benefits in your projects over time.


What programming principles do you find most valuable in your frontend development? Share your experiences in the comments below!


Profile picture

written by english-everyday
Eat, sleep, WRITE, Judo repeat... Twitter