برچسب: Creation

  • Mark a class as Sealed to prevent subclasses creation | Code4IT

    Mark a class as Sealed to prevent subclasses creation | Code4IT


    Just a second! 🫷
    If you are here, it means that you are a software developer.
    So, you know that storage, networking, and domain management have a cost .

    If you want to support this blog, please ensure that you have disabled the adblocker for this site.
    I configured Google AdSense to show as few ADS as possible – I don’t want to bother you with lots of ads, but I still need to add some to pay for the resources for my site.

    Thank you for your understanding.
    Davide

    The O in SOLID stands for the Open-closed principle: according to the official definition, “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”

    To extend a class, you usually create a subclass, overriding or implementing methods from the parent class.

    Extend functionalities by using subclasses

    The most common way to extend a class is to mark it as abstract :

    public abstract class MyBaseClass
    {
      public DateOnly Date { get; init; }
      public string Title { get; init; }
    
      public abstract string GetFormattedString();
    
      public virtual string FormatDate() => Date.ToString("yyyy-MM-dd");
    }
    

    Then, to extend it you create a subclass and define the internal implementations of the extention points in the parent class:

    public class ConcreteClass : MyBaseClass
    {
      public override string GetFormattedString() => $"{Title} | {FormatDate()}";
    }
    

    As you know, this is the simplest example: overriding and implementing methods from an abstract class.

    You can override methods from a concrete class:

    public class MyBaseClass2
    {
      public DateOnly Date { get; init; }
      public string Title { get; init; }
    
      public string GetFormattedString() => $"{Title} ( {FormatDate()} )";
    
      public string FormatDate() => Date.ToString("yyyy-MM-dd");
    }
    
    public class ConcreteClass2 : MyBaseClass2
    {
      public new string GetFormattedString() => $"{Title} | {FormatDate()}";
    }
    

    Notice that even though there are no abstract methods in the base class, you can override the content of a method by using the new keyword.

    Prevent the creation of subclasses using the sealed keyword

    Especially when exposing classes via NuGet, you want to prevent consumers from creating subclasses and accessing the internal status of the structures you have defined.

    To prevent classes from being extended, you must mark your class as sealed:

    public sealed class MyBaseClass3
    {
      public DateOnly Date { get; init; }
      public string Title { get; init; }
    
      public string GetFormattedString() => $"{Title} ( {FormatDate()} )";
    
      public string FormatDate() => Date.ToString("yyyy-MM-dd");
    }
    
    public class ConcreteClass3 : MyBaseClass3
    {
    }
    

    This way, even if you declare ConcreteClass3 as a subclass of MyBaseClass3, you won’t be able to compile the application:

    Compilation error when trying to extend a sealed class

    4 reasons to mark a class as sealed

    Ok, it’s easy to prevent a class from being extended by a subclass. But what are the benefits of having a sealed class?

    Marking a C# class as sealed can be beneficial for several reasons:

    1. Security by design: By marking a class as sealed, you prevent consumers from creating subclasses that can alter or extend critical functionalities of the base class in unintended ways.
    2. Performance improvements: The compiler can optimize sealed classes more effectively because it knows there are no subclasses. This will not bring substantial performance improvements, but it can still help if every nanosecond is important.
    3. Explicit design intent: Sealing the class communicates to other developers that the class is not intended to be extended or modified. If they want to use it, they accept they cannot modify or extend it, as it has been designed in that way by purpose.

    This article first appeared on Code4IT 🐧

    Wrapping up

    I hope you enjoyed this article! Let’s keep in touch on Twitter or LinkedIn! 🤜🤛

    Happy coding!

    🐧





    Source link

  • Bolt.new: Web Creation at the Speed of Thought

    Bolt.new: Web Creation at the Speed of Thought


    What Is Bolt.new?

    Bolt.new is a browser-based AI web development agent focused on speed and simplicity. It lets anyone prototype, test, and publish web apps instantly—without any dev experience required.

    Designed for anyone with an idea, Bolt empowers users to create fully functional websites and apps using just plain language. No coding experience? No problem. By combining real-time feedback with prompt-based development, Bolt turns your words into working code right in the browser. Whether you’re a designer, marketer, educator, or curious first-timer, Bolt.new offers an intuitive, AI-assisted playground where you can build, iterate, and launch at the speed of thought.

    Core Features:

    • Instantly live: Bolt creates your code as you type—no server setup needed.
    • Web-native: Write in HTML, CSS, and JavaScript; no frameworks required.
    • Live preview: Real-time output without reloads or delays.
    • One-click sharing: Publish your project with a single URL.

    A Lean Coding Playground

    Bolt is a lightweight workspace that allows anyone to become an engineer without knowing how to code. Bolt presents users with a simple, chat-based environment in which you can prompt your agent to create anything you can imagine. Features include:

    • Split view: Code editor and preview side by side.
    • Multiple files: Organize HTML, CSS, and JS independently.
    • ES module support: Structure your scripts cleanly and modularly.
    • Live interaction testing: Great for animations and frontend logic.

    Beyond the Frontend

    With integrated AI and full-stack support via WebContainers (from StackBlitz), Bolt.new can handle backend tasks right in the browser.

    • Full-stack ready: Run Node.js servers, install npm packages, and test APIs—all in-browser.
    • AI-assisted dev: Use natural-language prompts for setup and changes.
    • Quick deployment: Push to production with a single click, directly from the editor.

    Design-to-Code with Figma

    For designers, Bolt.new is more than a dev tool, it’s a creative enabler. By eliminating the need to write code, it opens the door to hands-on prototyping, faster iteration, and tighter collaboration. With just a prompt, designers can bring interfaces to life, experiment with interactivity, and see their ideas in action – without leaving the browser. Whether you’re translating a Figma file into responsive HTML or testing a new UX flow, Bolt gives you the freedom to move from concept to clickable with zero friction.

    Key Features:

    • Bolt.new connects directly with Figma, translating design components into working web code ideal for fast iteration and developer-designer collaboration.
    • Enable real-time collaboration between teams.
    • Use it for prototyping, handoff, or production-ready builds.

    Trying it Out

    To put Bolt.new to the test, we set out to build a Daily Coding Challenge Planner. Here’s the prompt we used:

    Web App Request: Daily Frontend Coding Challenge Planner

    I’d like a web app that helps me plan and keep track of one coding challenge each day. The main part of the app should be a calendar that shows the whole month. I want to be able to click on a day and add a challenge to it — only one challenge per day.

    Each challenge should have:

    • A title (what the challenge is)
    • A category (like “CSS”, “JavaScript”, “React”, etc.)
    • A way to mark it as “completed” once I finish it
    • Optionally, a link to a tutorial or resource I’m using

    I want to be able to:

    • Move challenges from one day to another by dragging and dropping them
    • Add new categories or rename existing ones
    • Easily delete or edit a challenge if I need to

    There should also be a side panel or settings area to manage my list of categories.

    The app should:

    • Look clean and modern
    • Work well on both computer and mobile
    • Offer light/dark mode switch
    • Automatically save data—no login required

    This is a tool to help me stay consistent with daily practice and see my progress over time.

    Building with Bolt.new

    We handed the prompt to Bolt.new and watched it go to work.

    • Visual feedback while the app was being generated.
    • The initial result included key features: adding, editing, deleting challenges, and drag-and-drop.
    • Prompts like “fix dark mode switch” and “add category colors” helped refine the UI.

    Integrated shadcn/ui components gave the interface a polished finish.

    Screenshots

    The Daily Frontend Coding Challenge Planner app, built using just a few prompts
    Adding a new challenge to the planner

    With everything in place, we deployed the app in one click.

    👉 See the live version here
    👉 View the source code on GitHub

    Verdict

    We were genuinely impressed by how quickly Bolt.new generated a working app from just a prompt. Minor tweaks were easy, and even a small bug resolved itself with minimal guidance.

    Try it yourself—you might be surprised by how much you can build with so little effort.

    🔗 Try Bolt.new

    Final Thoughts

    The future of the web feels more accessible, creative, and immediate—and tools like Bolt.new are helping shape it. In a landscape full of complex tooling and steep learning curves, Bolt.new offers a refreshing alternative: an intelligent, intuitive space where ideas take form instantly.

    Bolt lowers the barrier to building for the web. Its prompt-based interface, real-time feedback, and seamless deployment turn what used to be hours of setup into minutes of creativity. With support for full-stack workflows, Figma integration, and AI-assisted editing, Bolt.new isn’t just another code editor, it’s a glimpse into a more accessible, collaborative, and accelerated future for web creation.

    What will you create?



    Source link