Questions tagged [static-classes]

In object oriented programming a static class is a class whose members must be accessed without an instance of the class. Its members must be created as static.

In object oriented programming a static class is a class whose members must be accessed without an instance of the class. Its members must be created as static.

289 questions
11
votes
3 answers

How to serialize non-static child class of static class

I want to serialize a pretty ordinary class, but the catch is it's nested in a static class like this: public static class StaticClass { [Serializable] public class SomeType { ... } } This code: StaticClass.SomeType obj =…
tenfour
  • 36,141
  • 15
  • 83
  • 142
10
votes
4 answers

Application service layer as static classes

In my ASP.NET MVC application, I have a project that contains all the business logic/service layer. This project interacts with my Database (Entity framework) which is located in a separate project. I wanted easy access to the service layer, so I…
Omar
  • 39,496
  • 45
  • 145
  • 213
9
votes
3 answers

Concept Behind Static classes in Java

Consider the following code class A { static class B{ int a = 0; } public static void main(String argc[]) { B var1 = new B(); B var2 = new B(); var1.a = 5; var2.a = 6; …
Jinu Joseph Daniel
  • 5,864
  • 15
  • 60
  • 90
8
votes
6 answers

Why are static classes used?

I have doubts on static class and static methods. From MSDN I understood that "Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class." So if we don't want to associate a…
7
votes
3 answers

Are static classes supported by Swift?

I would like to know if you can create static classes in swift similar to those in C# i.e. a class that cannot be instantiated which can only have static functions and static properties. Are these types of classes possible in swift? If not, what is…
J.beenie
  • 861
  • 10
  • 22
7
votes
2 answers

Variables in a Javascript module visible outside of it?

To start, I'm coming from a .NET world, where there are static classes (C#, also known as modules in VB) and instance classes - those you can instantiate. This question is about Javascript, where I'm trying to recreate the pattern I already know and…
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
7
votes
4 answers

When to use static classes and methods?

I have a general question...when should i be using static classes or static methods?.. I know the idea that static methods can be called without instantiating...and static classes should only be used for static methods?...but are there any…
Vishal
  • 12,133
  • 17
  • 82
  • 128
7
votes
2 answers

Mocking a Static Class

I have a static class that wraps some native methods from winspool: public static class WinSpool { [DllImport("winspool.drv")] public static extern int OpenPrinter(string pPrinterName, out IntPtr phPrinter, IntPtr pDefault); ... …
moogs
  • 8,122
  • 8
  • 44
  • 60
6
votes
2 answers

ASP.NET MVC, ActionFilters, static classes and passing data around

I'd like to hear your opinions and maybe better suggestions for the following scenario: I have define a custom ActionFilter that does some job and comes out with some value. I would like to use that value in controller actions and in models. Now, I…
User
  • 30,403
  • 22
  • 79
  • 107
6
votes
1 answer

Instance variable of a static nested class vs static variable of an outer class

I was using a static nested class in java for a particular use-case. A minimal example of the same is shown below: public class Foo { static int fooInner = getInner(); // CASE 1 private static class StaticFoo { int fooInner =…
paradocslover
  • 2,932
  • 3
  • 18
  • 44
6
votes
2 answers

Can I create non static Azure function class in C#, what are the consequences?

This non static class is required for constructor injection in Azure function and collection of custom telemetry events. If we create an azure function app in visual studio, it creates default with static keyword like this: public static async…
6
votes
1 answer

Storing data in a static class [PHP]

Hi everyone and Merry Christmas! I am having some trouble with efficiency and I am hoping the StackOverflow community can help me. In one of my (static) classes, I have a function that takes a large amount of information from my database, parses…
camrymps
  • 327
  • 3
  • 11
6
votes
4 answers

Why can't I create extension methods for static classes?

When I try to create an extension method for the File class, I get an error telling me that I cannot do this because the class is static. However, I don't see why this stops the creation of an extension method, what implication is there? Thanks
GurdeepS
  • 65,107
  • 109
  • 251
  • 387
6
votes
2 answers

C++ High performance unit testing with Google Mock?

I'm using Google Mock, and I'm struggling to mock out C++ system calls (specifically the C++11 chrono functions). I'm know I'm supposed to make an interface, create a class to implement the interface for my actual implementation, and then mock out…
Zak
  • 12,213
  • 21
  • 59
  • 105
6
votes
1 answer

Why can an abstract class not be sealed or static?

Why can an abstract class not be sealed or static? And I am also confused about the question Why declare static classes as sealed and abstract in C#?.
anomepani
  • 1,796
  • 2
  • 25
  • 34
1 2
3
19 20