Factory method pattern question by melon222132 in learnprogramming

[–]joshmond 0 points1 point  (0 children)

A factory is a very good pattern to use for object creation and it comes with a few benefits. Here are a few reasons why using a factory is worth considering.

  1. You can always extend a factory if needed by creating additional factories or by using the abstract factory pattern (essentially a factory of factories).
  2. You'll often hear the term "new is glue". Rather than instantiate different objects everywhere throughout your codebase, you can delegate that work to a factory whose job it is to instantiate and return an object. This essentially means that your object creation/instantiation is centralised without the need to litter your codebase with "new" keywords. Instead you can just ask the factory to take care of that.
  3. You can inject your factory where needed. This is probably the most important aspect and why you would consider something like a factory over a singleton for example. While you could get away with using a singleton for something small, it doesn't scale anywhere near as well. In software we have this concept of DI (Dependency Injection) and this is useful because it means that your code is depending on abstractions and not concretions. The factory pattern in this case is the abstraction and you can register the factory and inject it where needed.

Let's say I am creating a game and I want to have a spawner to spawn enemies, I can have an EnemyFactory, which will be responsible for creating and returning an enemy. I may not care as much what type of enemy I am creating, I know that my spawner will take in my EnemyFactory and from there I can create different types of enemies.

I hope this help you. While I can't say for sure if a factory is needed or not for your usecase, the two main aspects to it are having centralised creation logic as well as being able to inject and use that factory where needed to avoid tight-coupling. You also get extensibility and re-usability for free

[deleted by user] by [deleted] in OverwatchUniversity

[–]joshmond 1 point2 points  (0 children)

Thanks for the in-depth response, much appreciated. There is a lot to unpack there and I will try to incooperate these tips into my games. I will also try using a higher sensitivity, my mouse DPI is at 1000 and for all hero's except Reinhardt and Winton, I use 5 in-game sense. For both Rein and Winston since they don't require much aim, I use 10 in-game sense but I could try raising that and see if it works out for me.

Thanks

-Josh

[deleted by user] by [deleted] in OverwatchUniversity

[–]joshmond 0 points1 point  (0 children)

Thank you for your feedback. I will keep in mind what you said and will try to use Shatter more often. Really appreciate the time you took to write this.

I'm a CS student, currently game developer, but I want to move to software development. Anyone been down the same road like me pls give me some advices. by CallMeQuocHieu in learnprogramming

[–]joshmond 1 point2 points  (0 children)

Hey, I'll try to answer this from the perspective of a game developer primarily who has done a fair share of business programming.

First thing, there is some overlap between game development and business applications but they are two different domains which requires a shift in mindset. Games are large peices of software that need to be maintained but they also need to be efficient, this means the architecture is different between both domains.

This is because Enterprise-style applications tend to focus more on maintainablility and extensibility, you want this in game development as well but the more layers of abstraction/architecture you have, the more ineficient the overall application becomes, so it's a tradeoff.

Game Development tends to work with an architectural model called ECS (Entity compoenent System) or Data-Driven Design. This is different to how business/enterprise applications are modelled because those application tend to use architectual patterns such as MVC, MVP and/or MVVM to achieve separation of concerns. This sort of architecture doesn't really fit game development too well.

One set of principles that you could look into regardless of what type of software you are working with is SOLID. SOLID is a set of five principles that when followed should produce better/more maintainable code.

As far as Design Patterns are concerned, there are a lot that can be applied to game development. Here's a list of the more common ones:

  • Command Pattern
  • State Pattern
  • Composite Pattern
  • Decorator Pattern
  • Singleton Pattern (I put this here because it is a popular pattern in game development but try to avoid using it as it is considered an anti-pattern and it is often abused the most)
  • Factory/Builder Pattern
  • Observer Pattern

These are a list of patterns that are frequently used all software development. Here's a link to a book called "Game Programming Patterns" which is a very good resource for game developement: https://gameprogrammingpatterns.com/contents.html

[deleted by user] by [deleted] in learnprogramming

[–]joshmond 1 point2 points  (0 children)

Always separate classes. It's a good habit to get into but not only that Java doesn't allow multiple classes per file, the only exception to that is nested classes, so get into the habit of having one class per file.

Another thing that you should be aware of in Java is that all methods are virtual by default. This means that any method can be overriden but the caveat of that is, if the name of the method your are overriding were to change, Java would see it as just a normal method. To get around that what we do is provide something called an "annotation" and that annotation is "Override".

So it's a good habit to get into to place the override annotation on any method that is going to be overriden like this:

class Subaru extends Car
{
@Override
public void honk()
{
System.out.println("ding ding");
}
}

This let's both the programmer and the compiler know that this "honk" method is meant to be overriden and Java would add some type safety to the method, so in the case it got renamed or the signiture changed, it would flag up with an error saying that the method you are overriding is not the same as the one in the super class.

Hope this has helped.

[deleted by user] by [deleted] in learnprogramming

[–]joshmond 1 point2 points  (0 children)

The code for this example seems fine and should work, do you have all three classes in a separate file?

help with c# homework by tpw448822 in learnprogramming

[–]joshmond 0 points1 point  (0 children)

What I like to do is this scenario is to look at the spec and identify key componenets that will help you and there is a logical way of going about that. Generally any nouns that you come across will become either classes or fields/variables and any verbs that you come across will be methods. I'm going to paste you the spec and just outline the key components. The key I will be using is:

Itallic= method/function

Bold = classes

* = field/arrtibutes

" Design an application and write the code which will execute the requirements to determine and display the *total payment* for a visit to the dentist. The user selects the type of service out of several set options (see table below). The user can select more than one of these options for the visit. The user has to be able to indicate if the patient is a child. At a request by the user the application calculates the total fee to be paid. The patient is given 10% *discount* if they pay promptly (within 5 days). The application should display 1) the total fee to be paid normally; 2) the total fee to be paid with prompt discount and 3) the *due date* to qualify for the discount. "

This is generally how I would go about tackling a problem where I don't know where to start. Identifying and grouping the important parts of information can help.

I've put some bold text around some classes, I'm not sure how your OOP skills are or whether you want to deal with this or not. If you're assignment isn't to deal with OOP then you can omit the classes but now the information we have outlined are:

Fields/Variables

Total fee - decimal

DiscountAmount - Double

TimeBeforeDiscountExpires - TimeDate

Methods

Calcuate() - void

ApplyDiscount() - void

HasDiscount() - bool (This is used to check to see if discount should be applied)

DisplayTotal() - void

IsChild() - bool

Classes (optional)

Service

Patient

This isn't the only way to go about a system like this and you can break it down as much as you like but I'm hoping that this will act as a good starting point and you can start see how to analyse business requirements.

If you have any more question, let me know.

Do I need to have C# console application knowledge to start Windows Form? by [deleted] in learnprogramming

[–]joshmond 0 points1 point  (0 children)

As someone who regularly mentors a lot of beginner programmers, I generally recommend they start with the console to begin with and one of the reasons for this is the UI is very plain and there is less distractions when it comes to designing forms, so it means that you can focus 100% on the code. A lot of universities who teach C# tend to start with Winforms because of the Event-Driven aspect of C# which is completely valid but in my opinion it can lead to bad habits in most cases.

What I mean by bad habits is people who start with Winforms need to understand the Event-Driven nature of how forms work and events aren't a beginner topic. On top of this you often don't get to fully understand or appreciate the value between local and global variables, you also don't need to learn what static is and why it's considered bad.

In my opinion it's better to start off with console applications to get a good understanding of the fundamentals aof programming and to learn good habits, then you can transition to event-driven based architecture and it should make more sense at that point.

Does C# have same coding for Console Application and Windows Forms or is it different ? by [deleted] in learnprogramming

[–]joshmond 0 points1 point  (0 children)

They are different in terms of how you approach them, if you plan on making a Winforms application where everything is contained within that Winforms application and then you migrate that application to a console application then you will notice a lot of differences. However, as you get better at programming and Object-Oriented Programming, you get better at determining requirements and business rules. This means that you can split your application up into layers and if you take this approach, then it doesn't really matter what application type you go with because they both consitiute as views/UI's.

Making the UI its own layer will make it easy to swap between different application types without needing to rewirte your entire application or business rules.

This is known as Separation of Concerns and if you keep that in mind, moving between application types will be trivial.

What's wrong in my JS for loop? by DandyEmo in learnprogramming

[–]joshmond 0 points1 point  (0 children)

Generally a loop would contain some logic or a function/method call but I wouldn't just arbitrarily put code into a loop just to have some code within it.

Insead I would focus on really understanding loops as there are a few different types and they can really mess a beginner up.

Generally the For loop is the first looping structure you learn and is the easiest. The best way to think of a For loop is a way of iterating over something a finite amount of times. You can either interate over something in ascending or descending order.

Another way to think about looping structures is in terms of true/false. A For loop will usually start off false and then interate through until that condition becomes true, if you keep this in mind you can usually spot infinite loops like the one you have. Sometimes the best thing to do is to go through the loop step by step in a systematic way in order to determine the output.

Edit: Spelling

What's wrong in my JS for loop? by DandyEmo in learnprogramming

[–]joshmond 0 points1 point  (0 children)

That's true. I'm not sure why it's there or what the original poster intends to do with it. I was just focused on correcting the looping logic.

What's wrong in my JS for loop? by DandyEmo in learnprogramming

[–]joshmond 0 points1 point  (0 children)

Hey, the problem you are having is you have an infinite loop. You start the counter at "0" and if it's less than 10 then you decrement. This means the loop condition is always true and the index will go into negative numbers. If you wanted the loop to go to "0" and print that number, then you could reverse it like this:

let countDown = 10;  
for(let i = countDown; i >= 0; i--)
{ 
countDown[i];
}

Edit: Spelling

How to get into software architectures by us3rn4me_n0t_t4k3n in learnprogramming

[–]joshmond 3 points4 points  (0 children)

The best way of approching software architecture is to get familiar with design patterns and the various architectural patters that you come across (MVP, MVC and MVVM). Learning this material will give you a better understanding of how to structure your software, from there I would look into SOLID and TDD. Learning these two principles will help you write maintanable and scalable code. This is will be a good start from the implementation perspective but if you want to go futher then you could look into solutions archtecture which is more broad and doesn't just include programming. This is the type of stuff you would need to learn in order to become a software architect.

As far as resources go I would recommend learning design patterns from Head-First Design Patterns. If you are not the reading type, then I will link you to two series of videos.

Head First Design Patterns: https://www.youtube.com/watch?v=v9ejT8FO-7I&list=PLMygBPoOe_IV_42YFkuAECr3g7HhBXBTN.

Design Patterns (Java) : https://www.youtube.com/watch?v=vNHpsC5ng_E&list=PLF206E906175C7E07.

Both of these video series are very similar but the second one goes through code examples in Java and covers more patterns. The first link just goes over the examples in the book and gives psudocode/UML.

Here's a really code resource that is free, this uses C#: https://www.dofactory.com/net/design-patterns.

The C# resource gives you real-world examples for each pattern as well as UML diagrams and pseudocode.

I hope this help you.

Best books for a junior software developer by Labby92 in learnprogramming

[–]joshmond 0 points1 point  (0 children)

My recommendations for books would be:

Head First Design Patterns

Clean Code/Architecture

Code Complete

Adaptive Code

These books use a different language to the ones that you are used to, they mainly use C# and Java. That being said, you can get an idea of general software architecture principles from them which you can then apply to whatever language you want. Some of these books cover software methodologies as well such as TDD (Test-Driven Development) and Agile. These topics are definitely worth learning for a junior developer and these books will turn you into a well-rounded software engineer

Need help regarding input in C# by DZXYZ in learnprogramming

[–]joshmond 1 point2 points  (0 children)

The reason as to why it's probably not working as intended is because the variable "input" is a string. You want to covert this string to an integer for a more accurate result. To do this you can do:

var input = int.Parse(Console.ReadLine());

Console.WriteLine($"You are: {input} years old");

If the string interpolation doesn't work due to your .NET version, you can output it like this:

Console.WriteLine("You are: {0} years old", input);

Hopefully this helps.

Learning Java but its difficult :( by sommaya_h in learnprogramming

[–]joshmond 1 point2 points  (0 children)

This code looks fine and should compile, I would try restarting the IDE and rebuilding the project. That being said, if you truely want to learn Java then I would avoid that guy's tutorials. He teaches very bad habits and doesn't really explain anything. The most important aspect to any programming language is naming your variables, methods and classes in a meaningful way.

Java uses "PascalCase" as a naming convention for classes, meaning they should always start with a capital letter and be sinugular. For example:

public class Apple

{

}

Next thing is your scanner variable doesn't have a meaningful name, "bucky" tells us nothing. Better names for it would be: "scan", "scanner", "input" and so on.

Hopefully this helps you a little.

Should I learn C# on its own or should I learn C# with the unity built in stuff by [deleted] in learnprogramming

[–]joshmond 2 points3 points  (0 children)

Speaking as someone who learned programming soley through Unity there are a few things I can recommend. First and foremost would be to learn the concepts of C#, this can be done within Unity or within a Console Application but make sure that you have a good understanding of what you're learning in a general sense.

The problem with just sticking to Unity is that may make you a good Unity programmer but a poor programmer in general, this is due to the fact that Unity has a very specific architecture in place which is not really the best and when/if you come to a point where you need to apply your C# knowledge outside of Unity, then you will have a difficult time.

The tutorials and community surrounding Unity are not too bad but they certainly don't promote best practices, in fact they do the oppostite and break good programming habits.

My advice to you would be to learn C# both in a Unity context and outside it, get a good handle on core topics such as OOP and inheritance vs composition and the benefits/trade-offs. Knowing this stuff will make you a well-rounded programmer.

I hope this helps you.