<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:tt="http://teletype.in/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Ars</title><generator>teletype.in</generator><description><![CDATA[Ars]]></description><link>https://teletype.in/@ars_kylnyk?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=ars_kylnyk</link><atom:link rel="self" type="application/rss+xml" href="https://teletype.in/rss/ars_kylnyk?offset=0"></atom:link><atom:link rel="next" type="application/rss+xml" href="https://teletype.in/rss/ars_kylnyk?offset=10"></atom:link><atom:link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></atom:link><pubDate>Sun, 22 Nov 2026 19:25:34 GMT</pubDate><lastBuildDate>Sun, 22 Nov 2026 19:25:34 GMT</lastBuildDate><item><guid isPermaLink="true">https://teletype.in/@ars_kylnyk/NE1fd8etoeS</guid><link>https://teletype.in/@ars_kylnyk/NE1fd8etoeS?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=ars_kylnyk</link><comments>https://teletype.in/@ars_kylnyk/NE1fd8etoeS?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=ars_kylnyk#comments</comments><dc:creator>ars_kylnyk</dc:creator><title>Liskov Substitution Principle (LSP)</title><pubDate>Mon, 05 May 2025 12:23:13 GMT</pubDate><description><![CDATA[Liskov Substitution Principle (LSP)]]></description><content:encoded><![CDATA[
  <p id="Giwh"><strong>Liskov Substitution Principle (LSP)</strong></p>
  <ul id="NAkU">
    <li id="ugfh"><strong>Definition</strong>: Objects or components should be replaceable with instances of their subtypes without altering the correctness of the program.</li>
    <li id="eBE0"><strong>In React</strong>: When creating components or extending them, ensure they can be used interchangeably without breaking the application.</li>
  </ul>
  <p id="RqHQ"><strong>Not following LSP:</strong> In this example, incorrect use of interface methods and not following the base interface for the same type of component violates the LSP principle.</p>
  <pre id="HgeN">// ❌ BAD EXAMPLE - Violating LSP
interface BadBaseButton {
  onClick: () =&gt; void;
  text: string;  // Restricts to string only
}

const BadBaseButton: React.FC&lt;BadBaseButton&gt; = ({ onClick, text }) =&gt; (
  &lt;button onClick={onClick}&gt;{text}&lt;/button&gt;
);

// Violates LSP by changing prop structure and behavior
interface BadPrimaryButton {
  label: string;  // Different prop name
  onAction: (e: React.MouseEvent) =&gt; Promise&lt;void&gt;;  // Different type
}

const BadPrimaryButton: React.FC&lt;BadPrimaryButton&gt; = ({ label, onAction }) =&gt; {
  const handleClick = async (e: React.MouseEvent) =&gt; {
    await onAction(e);
  };

  return &lt;button onClick={handleClick}&gt;{label.toUpperCase()}&lt;/button&gt;;
};

// Usage shows incompatibility
const BadExample: React.FC = () =&gt; {
  const handleClick = () =&gt; console.log(&#x27;clicked&#x27;);

  return (
    &lt;div&gt;
      &lt;BadBaseButton
        onClick={handleClick}
        text=&quot;Click me&quot;
      /&gt;

      {/* Won&#x27;t work! Different props and behavior */}
      &lt;BadPrimaryButton
        label=&quot;Click me&quot;
        onAction={async (e) =&gt; console.log(&#x27;clicked&#x27;)}
      /&gt;
    &lt;/div&gt;
  );
};
</pre>
  <p id="iVYR"><strong>Following LSP:</strong> It helps to ensure ****base props are extended consistently, the same onClick type throughout, components are interchangeable &amp; add features without breaking the base contract.</p>
  <pre id="RFYZ">// ✅ GOOD EXAMPLE - Following LSP
interface GoodBaseButtonProps {
  onClick: () =&gt; void;
  children: React.ReactNode;
}

const GoodBaseButton: React.FC&lt;GoodBaseButtonProps&gt; = ({ onClick, children }) =&gt; (
  &lt;button onClick={onClick}&gt;{children}&lt;/button&gt;
);

// Properly extends base props
interface GoodPrimaryButtonProps extends GoodBaseButtonProps {
  variant?: &#x27;solid&#x27; | &#x27;outline&#x27;;  // Optional additional prop
}

const GoodPrimaryButton: React.FC&lt;GoodPrimaryButtonProps&gt; = ({
  onClick,
  children,
  variant = &#x27;solid&#x27;
}) =&gt; {
  const className = variant === &#x27;solid&#x27; ? &#x27;bg-blue-500&#x27; : &#x27;border-blue-500&#x27;;

  return (
    &lt;button onClick={onClick} className={className}&gt;
      {children}
    &lt;/button&gt;
  );
};

// Usage shows compatibility
const GoodExample: React.FC = () =&gt; {
  const handleClick = () =&gt; console.log(&#x27;clicked&#x27;);

  return (
    &lt;div&gt;
      {/* Both components can use the same handler */}
      &lt;GoodBaseButton onClick={handleClick}&gt;
        Click me
      &lt;/GoodBaseButton&gt;

      &lt;GoodPrimaryButton onClick={handleClick} variant=&quot;solid&quot;&gt;
        Click me
      &lt;/GoodPrimaryButton&gt;
    &lt;/div&gt;
  );
};
</pre>
  <p id="nQvS">x</p>

]]></content:encoded></item></channel></rss>