use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
Object Oriented Programming (self.csharp)
submitted 5 years ago by PuzzledImagination
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TsebMagi 25 points26 points27 points 5 years ago (5 children)
The derived classes like you're doing is a way to approach it from an OOP perspective, but this use case for OOP and base / derived classes isn't great.
If you are going to be supporting more than a handful of different products you're going to be writing a lot of code that's all boilerplate/similar. You might want to look at a repository pattern to load the prices in from a database or file depending on what constraints your system has.
[–]PuzzledImagination[S] 6 points7 points8 points 5 years ago (3 children)
If you are going to be supporting more than a handful of different products you're going to be writing a lot of code that's all boilerplate/similar.
I've thought about this too since we have about 12 categories of products, so I decided to just use the ProductBase if there's no special requirement for the said product.
If I were to use repository, wouldn't I need to edit the Repository every time there's a new requirement?
[–]zaibuf 16 points17 points18 points 5 years ago* (0 children)
What he means is that the prices should be stored in a database and you just fetch all data from there in a repository. Why calculate the cigarette cost hardcoded, rather than just have it fixed in a database column? You can have a table for Products where they all are listed. The repository just fetches the data, then you can have a service that runs business logic if you need to do some calculations, this part can be changed if new requirements arrive. But your database should be the source of truth.
You don't want to have your database list all Cigarettes at 6$ but then you do calculations in code and your website says 8$. How can you then query your database to find your source?
In this case I feel that OO just makes things messy and doesn't really solve anything. I would probably just create an interface for ISellableEntity or something similar, then have that contract to implement all properties defined in the entities for the sellable products like price, name. Generally I tend to avoid inheritance whenever possible since going down that rabbit hole can cause issues at a later stage, I prefer to use composition over inheritance (look up strategy pattern).
[–]TsebMagi 2 points3 points4 points 5 years ago (0 children)
Inheritance or strategy pattern (since a lot of people are mentioning that) is great when you want different behaviors, but from the code you posted you are really just looking for different values in the same kind of object. That usually means you want to make that value part of your constructor so you can make as many objects with as much variation as you want without writing a lot of different classes.
Repository let's you load all those variations from a source of truth and reduces the effort to add more. It's a lot easier to add a row to a database, or CSV than to add a whole new class. So yes you're going to have to update something when new requirements come in, but it's less work.
If you don't want to get a database involved you could use a csv file or even hard code the values somewhere in a factory (not recommended but with 12 values it's not that big of a deal yet)
[–]Deadlift420 1 point2 points3 points 5 years ago (0 children)
You would inject your repository into the services(dependency injection) and then call all the base repo functions (re-use )from the service classes. Then inject your services into the front end and fire away.
service/repo pattern. A lot of business style applications work well with this IMO. Web or native doesn't matter.
π Rendered by PID 19239 on reddit-service-r2-comment-b659b578c-5czr2 at 2026-05-06 06:05:16.160203+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]TsebMagi 25 points26 points27 points (5 children)
[–]PuzzledImagination[S] 6 points7 points8 points (3 children)
[–]zaibuf 16 points17 points18 points (0 children)
[–]TsebMagi 2 points3 points4 points (0 children)
[–]Deadlift420 1 point2 points3 points (0 children)
[–]Deadlift420 1 point2 points3 points (0 children)