#Design #Lessons
Notification Psychology Lab · Learn what makes notifications hard to ignore https://ilo.im/162rnr
_____
#Course #Notifications #Psychology #DesignPatterns #DeceptiveDesign #ProductDesign #UxDesign #UiDesign #WebDesign
#Design #Lessons
Notification Psychology Lab · Learn what makes notifications hard to ignore https://ilo.im/162rnr
_____
#Course #Notifications #Psychology #DesignPatterns #DeceptiveDesign #ProductDesign #UxDesign #UiDesign #WebDesign
I am beginning to favor 'explicit' over 'implicit' programming.
No guesswork. Limited risks.
You know exactly what you're in for.
Don't play Plinko with data.
Be explicit.
@brandon_rhodes 's Python Design Patterns explores why many traditional OO patterns are irrelevant to Python, with its first class functions, optional arguments, etc.
We have a "rules engine" in a database. Another application uses it for a specific task.
The rules are ranked just like a "search engine".
There's no real apparatus to regression test this thing when you update a rule.
Did it break another rule? I don't know. I can't manually test all possible permutations of each rule. That's what automation is for.
I need something .. to test all this.
Recommendations?
Feels like this is designed....bad
Generic Repository Pattern in C#
Have you ever dreaded writing the same boilerplate repository code repeatedly? You’re not alone; I will share my implementation of the Code First Generic Repository Pattern in C#. I will only include some of the code because it will make the post incredibly long. At the end of the post, I will share a Goal donation to post a Git download link so you can take it for a spin. As a bonus, the repository uses Code First and Unit of Work.
Generic Repository Pattern in C#
Let’s begin with the Entity interface. The IEntity interface is a typical pattern used in software development to define a contract for entities, typically in the context of data access and persistence. It usually includes a property for the entity’s unique identifier. The Generic Type: The IEntity interface uses a generic type parameter TKey to allow flexibility in the type of the identifier (e.g., int, Guid, string). The ID property will identify each entity uniquely. Feel free to read more about the implementation at the entity framework core generic repository and Structured Query IEntity.
public interface IEntity<TKey>{ TKey Id { get; set; }}
You might find the following definition of the generic repository pattern on the interwebs.
The Generic Repository pattern in C# is a design pattern that abstracts the application’s data layer, making it easier to manage data access logic across different data sources. It aims to reduce redundancy by implementing typical data operations in a single, generic repository rather than having separate repositories for each entity type.
public interface IGenericRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>{ void Delete(TEntity entityToDelete); TEntity? GetFirstOrDefault(Expression<Func<TEntity, bool>> predicate); void Update(TEntity entityToUpdate); void Save(); void Dispose();}
The interface header has two generic types. TEntity is the domain class, and the TKey is the ID type, int, or string. Note that IEntity abstracts away the type TKey. It looks complex for the moment, but you will see benefits later.
Moving away from the Generic Repository, let’s focus on the pattern of the Unit of Work. According to Copilot:
The Unit of Work is a design pattern used in software development to manage and coordinate changes to a database. It ensures that all operations within a single business transaction are treated as a single unit, which means they either all succeed, or all fail together. This helps maintain data integrity and consistency.
public interface IUnitOfWork : IDisposable{ IGenericRepository<TEntity, TKey> Repository<TEntity, TKey>() where TEntity : class, IEntity<TKey>; void Save(); Task<int> SaveAsync();}
The Unit of Work will allow us later to inject it as a service for any repository. If you inspect the interface closely, you will notice it has three fields. The most vital of the three is the Repository. The method returns a domain of type repository and key. You can specify the type when using it.
Moving on to the Code First portion, we must tell Entity Framework how to build our database. To do so, we can create a “BloggingContext”.
public class BloggingContext: DbContext{ // Use design time factory public BloggingContext(DbContextOptions<BloggingContext> dbContextOptions) : base(dbContextOptions) { } public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; }}
If you inspect the code closely, you will notice that we inherited from DbContext, which allows us to manipulate the database. The DbContext will also enable us to use DbSets and CRUD methods. You can read more about DbContext Class on the Microsoft website.
Before using your Database Context with Code, you must set up migrations. Migrations allow you to evolve your database as you code and change the schema. I recommend you read up on Migrations managing schemas because it has excellent examples to help you start quickly.
At the high level, in Visual Studio, open up the Tools menu, then the NuGet Package Manager menu, followed by the Console. In the Console, you must install the following package.
Install-Package Microsoft.EntityFrameworkCore.Tools
The Microsoft.EntityFrameworkCore.Tools will allow you to make the following commands.
Add-Migration InitialCreate
Update-Database
Meanwhile, you might want to consider making a DesignTimeDbContextFactory because it aids in setting up the connection string for the database.
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BloggingContext>{ public BloggingContext CreateDbContext(string[] args) { // Build configuration IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.Development.json") .Build(); // Get connection string var connectionString = configuration.GetConnectionString("DefaultConnection"); var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>(); optionsBuilder.UseSqlServer(connectionString); return new BloggingContext(optionsBuilder.Options); }}
I’m considering publishing the fully working example on Git with the following components.
Current Donation Amount
$2.41 – PayPal fees
Note that the donation amount is being updated manually on my end. I have asked WordPress; see the image for details. I will list your name and last name initials. If you like the website backlink, donate $10 or more, and let me know in the comments your web address.
Donate to Goal of $666 to unlock Code First Generic Repository Pattern
Upon reaching the $666 Goal, I will share the code.
$3.00
Donators List
#lispyGopherClimate Go Here Please: https://communitymedia.video/w/cRzNMeBMWGyV2URdZN9CtF
@screwtape@communitymedia.video and retoot
#climate #climateCrisis #senryu #haiku by @kentpitman https://climatejustice.social/@kentpitman/112718092451838500
#live ! #music from @xylander
https://xylander.bandcamp.com/album/hectic-life-busy-busy-busy
Beautiful #ErikSandewall #unix_surrealism . also #gopher transcript of Sandewall's inaugural statue speech on the new information science. gopher://triapul.cz/0/phlog/2024-07-03-erik-sandewall-speech.txt
Also note #ascii #art
Discuss the differences and best uses for the Strategy Pattern vs the Specification Pattern.
The 2nd Edition of Elecia( @logicalelegance ) Making Embedded Systems published by O'Reilly is out![in ebook form]
She has added 100+ pages, 4 new chapters, lots of ideas, tons of advice, a chicken button, and an eldritch horror.
You can get it wherever you find your electronic books (including Amazon, ebooks.com and Google Play).
Hard copies will be out in about two weeks and you can pre-order at
https://www.amazon.com/Making-Embedded-Systems-Elecia-White-ebook/dp/B0CWX167Q7/ now!
Dear #Fediverse, I ask you for #help
Recommend me some #books to buy on
• #Python (language)
• #Django
• #Accessibility (#web)
• #PostgreSQL
• #ArtificialIntelligence
• #DesignPatterns
• #FreeSoftware
• #OpenSource
I'd like to have
• author
• title
• suggestion reason
• purchase URL
I prefer #ePUB (more than Amazon and content with DRM), but #paperback is fine if there are no alternatives
Thank you
P.S. It's fine to propose books that you've written
P.P.S. #boost please
#specification pattern versus eliminating conditional logic via polymorphism.
Discuss.
We have a database "rules engine" that I greatly dislike. The maintenance of it is especially troubling.
It is essentially a huge Conditional statement. Which leads me to Martin Fowler's solution: conditionals as polymorphism.
Which led me to use JSON schemas to define the polymorphed classes at runtime. But #polymorphism in #json isnt quite that simple.
I've also considered the #specification pattern. But maintaining specifications is the issue.
Still thinking.
Wanting to explore ways to bring your team together? And make remote collaboration over video conferencing more fun and immersive? Then the Remote Interaction Guidelines are ready for you on MakerBox...
https://bbc.co.uk/makerbox/tools/remote-interaction-guidelines
You know how conforming to Codable makes it so any UIView subclass has to implement codable (even if it just is to fatalError() because you only ever plan to create the view in code).
Is there a good #Swift design pattern for creating class hierarchies like that? Where the base class supports and implements a feature, but you don't want subclasses to be forced to provide it?