Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I Started Learning C# and it confuses me with term 'outsiders'. Are outsiders some unauthorized people to our code?
It is not C# jargon, but it refers to any entity that is not the object.
In this specific case, outsiders might be the factory that creates the player or other entities of the game.
In general you want to grant access to specified resources only to a selected few. This maintains the code cleaner (as you force using specific accesses you appositely designed) and ensures the flow is followed (imagine that when setting the score you also want to update other variables of Player, if someone modified the variable directly, the side effects would be bypassed).
The whole situation becomes even more critical when you are writing a library for others: you want to encapsulate the internal variables as much as possible and not allow others to have "free access" to everything, as they might tamper with important stuff.
Outsiders is any other code outside of this object. So when you set variable as private, only code in this object can change it. That way you force any other code outside this class to modify score only by calling setScore method, and not directly accessing it.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I got some businesslogic I want to handle inside of a .cs file.
Depending on the outcome of that, I want to update the blazor UI, EG a toast notification or a variable change. How could I do that?
Thank you in advance.
This is not easy to answer as your question is not specific, and we don't know how proficient you are in programming. However, the following answer may illustrate the path you should take in the context of Blazor:
Your class should be defined as a service, which you should add to the DI container from the Startup class, and injected into your relevant components.
This service class, generally speaking, should implement two patterns: The State pattern and the Notifier pattern. The service is supposed to hold some state, as for instance, a given value passed to the service from component A, which trigger an event handler that propagate this fact to other subscribing components, passing them the new value passed from component A via EventArgs or properties. The complicity of the service depends on the functionality you want to expose.
Search Google for strings like "enet stackoverflow Blazor notifier", and such like to see relevant code provided in my answers.
See these links:
https://stackoverflow.com/a/62042629/6152891
https://stackoverflow.com/a/66370816/6152891
You need to use ComponentBase.StateHasChanged in response to whatever is happening in your business logic. Since you didn't post any code it's hard to be more specific but that method will force the relevant component to re-render.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
can you please tell me what is better to use?
for-each loop
create new object of class.
In mine case both aspect gave me same output.
so, my question is that what will i prefer to use.
If i choose 1st aspect.
whenever my page load at that time in fore-each loop(50 record fixed) will come.
and every time that loop execute so, my page execution is bit slower.
If i choose 2nd aspect
whenever my page load at that time new object is created and memory initialize
In asp.net mvc any inbuilt function or method to remove garbage collection(collection of unusual object) ?
please tell me what would i prefer for better use with relevant reason.
Write whichever one is simpler to code and more obviously correct. Then, see if your page is too slow or uses too much memory. (You get to decide what "too slow" or "too much" means, it's your application!)
If it works, great! Your problem is solved, work on adding more value to your application in some other way.
If it is too slow or uses too much memory, then try the less simple approach.
Then -- and this is the important part -- measure the difference for your application. Then, and only then, can you know the right answer.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
If I've some common functionality that I've to keep in a class, so will I go for static, sealed or abstract class...Does all these types of classes serve the purpose of keeping the common functionality together...where actually the difference lies when I've to go for one
abstract, sealed, static has nothing to do with real time development. It has to do with bring structure within your software, so that the functionality implemented in classes can and should be used in the right way.
After some comments i think this:
I think you can only learn this, by doing it. There isn't a book or epub that will explain you how to do programming. They will show the syntax and some examples. It will be trial and error. Every day you'll face a new challenge.
You'll have to practice it. The best advise is, look what others already created and try to imagine why did they wrote/solve it that way.
I can explain what a static/sealed/abstract class is/does, but it doesn't learn you when to use it.
Back to the question: Define 'real time'.. I think that static/abstract/sealed should NOT be decisive on how you write your 'real-time' software. If you are 'scared' about performance on this level, C# should not be your choise. I would write c++ or if you want a real challenge, try to beat the compilers with asm ;-)
I think you won't measure the 'overhead'
So, use abstract/static/sealed in a right way, so your future collega's/you can read/maintain it.
I use C# for communication (tcp/ip) between a windows computer and a PLC (with delta robots). But it's far from realtime. It's fast enough to keep many robot working with > 100 messages per second.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Are there any reasons why static classes in Asp.Net can lead to a security threat?
Do not objects just live in current session ?
Thank you!
Objects live in a so called AppPool in the IIS. As long as that is not recycled, objects with static lifetime will be available. As one cannot reliably know when recycling happens, having static variables is a bad idea either way. Using them to hold data between calls or assuming they will not hold data between calls is both equally dangerous.
That said, if your static class does not hold data and only consists of methods, that's perfectly fine.
Static class has no instance, and consequently you should not be keeping any state of any object in side them. So theoretically it shouldn't be an issue with the security of designed correctly.
Now static variables on the other side could cause security issue if used improperly.
For example if variable like isLoggedIn is static, once one person logs in, every other user is automatically logged in because the variable will be true for every instance of the class using it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is my first question here so let me know if additional info is required...
I am new to designing so my knowledge is a little limited, so I have this application in which I have a project class, the project goes through 7 stages, and those stages have nothing in common...first one is Discovery, which contains question about the requirements, second is Product Mapping, which lets the user select products required by the project...
The problem comes, that stages keep on getting added or removed...
So I cant put their reference in the class, cuz then I need to modify the class every time. So how to design the flow?
Should I pass the project object into stage object? Then how to keep track on which stage the project is?
I think you should go for Process Manager Pattern.
Each of your stages should be separate class implementing a common Interface/Abstract class(according to your need) and then you need to have a Controller class which will control the work flow of your project. You can add or remove your steps to this Controller class instance as per your requirement.
You can track the "status" of the Project as Project.status, being an enum that advances through the appropriate stages. (This assumes that each stage exists only once; it can be re-executed, but would update/ overwrite the previous results.)
Data captured at each stage can be implemented as properties in the Project class (most simple), or (more advanced) "pushed down" into composite entities per-stage.
Don't forget also to take advantage of entities/objects to hold information like Requirement, Product Mapping etc!