Search Results

Search found 23271 results on 931 pages for 'static classes'.

Page 10/931 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Significant amount of the time, I can't think of a reason to have an object instead of a static class. Do objects have more benefits than I think?

    - by Prog
    I understand the concept of an object, and as a Java programmer I feel the OO paradigm comes rather naturally to me in practice. However recently I found myself thinking: Wait a second, what are actually the practical benefits of using an object over using a static class (with proper encapsulation and OO practices)? I could think of two benefits of using an object (both significant and powerful): Polymorphism: allows you to swap functionality dynamically and flexibly during runtime. Also allows to add new functionality 'parts' and alternatives to the system easily. For example if there's a Car class designed to work with Engine objects, and you want to add a new Engine to the system that the Car can use, you can create a new Engine subclass and simply pass an object of this class into the Car object, without having to change anything about Car. And you can decide to do so during runtime. Being able to 'pass functionality around': you can pass an object around the system dynamically. But are there any more advantages to objects over static classes? Often when I add new 'parts' to a system, I do so by creating a new class and instantiating objects from it. But recently when I stopped and thought about it, I realized that a static class would do just the same as an object, in a lot of the places where I normally use an object. For example, I'm working on adding a save/load-file mechanism to my app. With an object, the calling line of code will look like this: Thing thing = fileLoader.load(file); With a static class, it would look like this: Thing thing = FileLoader.load(file); What's the difference? Fairly often I just can't think of a reason to instantiate an object when a plain-old static-class would act just the same. But in OO systems, static classes are fairly rare. So I must be missing something. Are there any more advantages to objects other from the two that I listed? Please explain.

    Read the article

  • Static route works on one computer, not the other

    - by Dan
    I have been struggling with this for a couple days now, maybe I just need some people with a fresh perspective to figure out what the issue is. Basically I have a bunch of computers that are being routed through a specific gateway in order to access a web page that is hosted internally on a separate subnet. I set up static routes on all of the computers, and they all work... except one. Here's what a route print -4 looks like for a working computer (Windows 7): =========================================================================== Interface List 14...xx xx xx xx xx xx ......Broadcom 802.11n Network Adapter 11...xx xx xx xx xx xx ......Realtek PCIe GBE Family Controller 1...........................Software Loopback Interface 1 12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter 13...00 00 00 00 00 00 00 e0 Microsoft 6to4 Adapter 17...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface =========================================================================== IPv4 Route Table =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 10.xxx.xxx.230 10.xxx.xxx.94 20 10.zzz.zzz.0 255.255.255.0 10.xxx.xxx.147 10.xxx.xxx.94 21 10.xxx.xxx.0 255.255.255.0 On-link 10.xxx.xxx.94 276 10.xxx.xxx.94 255.255.255.255 On-link 10.xxx.xxx.94 276 10.xxx.xxx.255 255.255.255.255 On-link 10.xxx.xxx.94 276 127.0.0.0 255.0.0.0 On-link 127.0.0.1 306 127.0.0.1 255.255.255.255 On-link 127.0.0.1 306 127.255.255.255 255.255.255.255 On-link 127.0.0.1 306 224.0.0.0 240.0.0.0 On-link 127.0.0.1 306 224.0.0.0 240.0.0.0 On-link 10.xxx.xxx.94 276 255.255.255.255 255.255.255.255 On-link 127.0.0.1 306 255.255.255.255 255.255.255.255 On-link 10.xxx.xxx.94 276 =========================================================================== Persistent Routes: Network Address Netmask Gateway Address Metric 10.zzz.zzz.0 255.255.255.0 10.xxx.xxx.147 1 =========================================================================== And here's a route print -4 from the station that doesn't work (also Windows 7): =========================================================================== Interface List 10...xx xx xx xx xx xx ......Realtek PCIe GBE Family Controller 1...........................Software Loopback Interface 1 12...00 00 00 00 00 00 00 e0 Microsoft 6to4 Adapter 14...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2 16...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface =========================================================================== IPv4 Route Table =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 10.xxx.xxx.230 10.xxx.xxx.132 276 10.zzz.zzz.0 255.255.255.0 10.xxx.xxx.147 10.xxx.xxx.132 21 10.xxx.xxx.0 255.255.255.0 On-link 10.xxx.xxx.132 276 10.xxx.xxx.132 255.255.255.255 On-link 10.xxx.xxx.132 276 10.xxx.xxx.255 255.255.255.255 On-link 10.xxx.xxx.132 276 127.0.0.0 255.0.0.0 On-link 127.0.0.1 306 127.0.0.1 255.255.255.255 On-link 127.0.0.1 306 127.255.255.255 255.255.255.255 On-link 127.0.0.1 306 224.0.0.0 240.0.0.0 On-link 127.0.0.1 306 224.0.0.0 240.0.0.0 On-link 10.xxx.xxx.132 276 255.255.255.255 255.255.255.255 On-link 127.0.0.1 306 255.255.255.255 255.255.255.255 On-link 10.xxx.xxx.132 276 =========================================================================== Persistent Routes: Network Address Netmask Gateway Address Metric 10.zzz.zzz.0 255.255.255.0 10.xxx.xxx.147 1 =========================================================================== Both of these stations are running Windows 7. So essentially what I am trying to do here is route all traffic to the 10.zzz.zzz.0 subnet through the 10.xxx.xxx.147 gateway. Everything else should go through the 10.xxx.xxx.230 gateway. This is the intended behavior, and again it is working everywhere but that one station. I noticed that the Active Route metric costs differ between the two stations, but I am new to the routing table and I am not sure how that is impacting the behavior. I hope I have been able to explain the situation clearly. Any help would be much appreciated. I can provide any additional information if needed!

    Read the article

  • Java: Non-static nested classes and instance.super()

    - by Kiv
    I'm having a hard time wrapping my head around non-static nested classes in Java. Consider the following example, which prints "Inner" and then "Child". class Outer { class Inner { Inner() { System.out.println("Inner"); } } } public class Child extends Outer.Inner { Child(Outer o) { o.super(); System.out.println("Child"); } public static void main(String args[]) { new Child(new Outer()); } } I understand that instances of Inner always have to be associated with an Outer instance, and that that applies to Child too since it extends Inner. My question is what the o.super() syntax means - why does it call the Inner constructor? I've only seen a plain super(args) used to call the superclass constructor and super.method() to call the superclass version of an overridden method, but never something of the form instance.super().

    Read the article

  • non-static method setPrzechowaj(java.lang.String) cannot be referenced froma a static context

    - by bigbluedragon
    hey i have problem with JDialogForm. I have created it using netbeans 6.8. That JDialogForm have textfield and button below it. and here is some code... private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String sciezka = jTextField1.getText(); if (sciezka.length() > 0) { Zmienne_pomocnicze.setPrzechowaj(sciezka); } } Now i want to copy that string "sciezka" to my main window but if I do it like this public class Zmienne_pomocnicze { public String n; public void setPrzechowaj (String neew) { n = neew; } public String getPrzechowaj () { return n; } } i get error in jButton1: non-static method setPrzechowaj(java.lang.String) cannot be referenced froma a static context any ideas?

    Read the article

  • Class Structure w/ LINQ, Partial Classes, and Abstract Classes

    - by Jason
    I am following the Nerd Dinner tutorial as I'm learning ASP.NET MVC, and I am currently on Step 3: Building the Model. One part of this section discusses how to integrate validation and business rule logic with the model classes. All this makes perfect sense. However, in the case of this source code, the author only validates one class: Dinner. What I am wondering is, say I have multiple classes that need validation (Dinner, Guest, etc). It doesn't seem smart to me to repeatedly write these two methods in the partial class: public bool IsValid { get { return (GetRuleViolations().Count() == 0); } } partial void OnValidate(ChangeAction action) { if (!IsValid) { throw new ApplicationException("Rule violations prevent saving."); } } What I'm wondering is, can you create an abstract class (because "GetRuleViolations" needs to be implemented separately) and extend a partial class? I'm thinking something like this (based on his example): public partial class Dinner : Validation { public IEnumerable<RuleViolation> GetRuleViolations() { yield break; } } This doesn't "feel" right, but I wanted to check with SO to get opinions of individuals smarter than me on this. I also tested it out, and it seems that the partial keyword on the OnValidate method is causing problems (understandably so). This doesn't seem possible to fix (but I could very well be wrong). Thanks!

    Read the article

  • Interface and partial classes

    - by Tomek Tarczynski
    According to rule SA1201 in StyleCop elements in class must appear in correct order. The order is following: Fields Constructors Finalizers (Destructors) Delegates Events Enums Interfaces Properties Indexers Methods Structs Classes Everything is ok, except of Interfaces part, because Interface can contain mehtods, events, properties etc... If we want to be strict about this rule then we won't have all members of Interface in one place which is often very useful. According to StyleCop help this problem can be solved by spliting class into partial classes. Example: /// <summary> /// Represents a customer of the system. /// </summary> public partial class Customer { // Contains the main functionality of the class. } /// <content> /// Implements the ICollection class. /// </content> public partial class Customer : ICollection { public int Count { get { return this.count; } } public bool IsSynchronized { get { return false; } } public object SyncRoot { get { return null; } } public void CopyTo(Array array, int index) { throw new NotImplementedException(); } } Are there any other good solutions to this problem?

    Read the article

  • Problem with inner classes of the same name in Visual C++

    - by starblue
    I have a problem with Visual C++, where apparently inner classes with the same name but in different outer classes are confused. The problem occurs for two layers, where each layer has a listener interface as an inner class. B is a listener of A, and has its own listener in a third layer above it (not shown). The structure of the code looks like this: A.h class A { class Listener { Listener(); virtual ~Listener() = 0; } [...] } B.h class B : public A::Listener { class Listener { Listener(); virtual ~Listener() = 0; } [...] } B.cpp B::Listener::Listener() {} B::Listener::~Listener() {} I get the error B.cpp(49) : error C2509: '{ctor}' : member function not declared in 'B' The C++ compiler for Renesas sh2a has no problem with this, but then it is more liberal than Visual C++ in some other respects, too. If I rename the listener interfaces to have different names the problem goes away, but I'd like to avoid that (the real class names instead of A or B are rather long). Is what I'm doing correct C++, or is the complaint by Visual C++ justified? Is there a way to work around this problem without renaming the listener interfaces?

    Read the article

  • C# "Enum" Serialization - Deserialization to Static Instance

    - by Walt W
    Suppose you have the following class: class Test : ISerializable { public static Test Instance1 = new Test { Value1 = "Hello" ,Value2 = 86 }; public static Test Instance2 = new Test { Value1 = "World" ,Value2 = 26 }; public String Value1 { get; private set; } public int Value2 { get; private set; } public void GetObjectData(SerializationInfo info, StreamingContext context) { //Serialize an indicator of which instance we are - Currently //I am using the FieldInfo for the static reference. } } I was wondering if it is possible / elegant to deserialize to the static instances of the class? Since the deserialization routines (I'm using BinaryFormatter, though I'd imagine others would be similar) look for a constructor with the same argument list as GetObjectData(), it seems like this can't be done directly . . Which I would presume means that the most elegant solution would be to actually use an enum, and then provide some sort of translation mechanism for turning an enum value into an instance reference. How might one go about this?

    Read the article

  • AS3 Classes - Should I use them?

    - by Eric
    I'm working on a project in Flash CS4/AS3 and I have a document class set up but I am wondering about using that, as opposed to frame-based scripting. Most of what I have seen so far deals with how to create them, but doesn't offer much about why or when to use them. I know I can also pull in other classes beyond the document class but, again, why and when? Could I get some input from you fine people out there on usage/best practice, etc? Thanks

    Read the article

  • Implementing Static Libraries In iPhone

    - by socialCircus
    Hi All, I have created a static library following this link. But I am facing Problems in using the library. For reference on how to use static libraries in an iPhone project I followed this link . But I am stil struggling with the "How to implement static libraries in any other iPhone project?" question. Thank you all.

    Read the article

  • Why doesn't Visual Studio show an exception message when my exception occurs in a static constructor

    - by Tim Goodman
    I'm running this C# code in Visual Studio in debug mode: public class MyHandlerFactory : IHttpHandlerFactory { private static Dictionary<string, bool> myDictionary = new Dictionary<string, bool>(); static MyHandlerFactory() { myDictionary.Add("someKey",true); myDictionary.Add("someKey",true); // fails due to duplicate key } } Outside of the static constructor, when I get to the line with the error Visual Studio highlights it and pops up a message about the exception. But in the static constructor I get no such message. I am stepping through line-by-line, so I know that I'm getting to that line and no further. Why is this? (I have no idea if that fact that my class implements IHttpHandlerFactory matters, but I included it just in case.) This is VS2005, .Net 2.0

    Read the article

  • Why static fields are not initialized in time?

    - by Tom Brito
    Somebody tell me: class MyClass { private static MyClass myClass = new MyClass(); private static final Object obj = new Object(); public MyClass() { System.out.println(obj); // will print null once } } I wonder, isn't this a bug? Why static objects are not initialized before the constructor runs?

    Read the article

  • partial classes/partial class file

    - by Ravisha
    In C# .net there is a provision to have two different class files and make them a single class using the keyword partial keyword.this helps it to keep [for ex]UI and logic seperate. of course we can have two classes to achieve this one for UI and other for logic. Can this be achieved in java some how?

    Read the article

  • Best Static Website Generator

    - by Nick Retallack
    In the age of dynamic websites built with layouts and templates, nobody wants to write plain old repetitive static html anymore. But now that you can outsource dynamic features to services like Disqus, and you could get slashdotted/dugg/reddited at any moment, sometimes a static website is best for scalability. There are quite a few static website generators out there that let you use templates, layouts, alternative markup languages, and other new age stuff. So this question is a bit of a survey. Which do you think is the best, and why? Here are a few examples to start us off: WebGen StaticMatic Static

    Read the article

  • Static analysis tool customization for any language

    - by Sam
    Hi, We are using a Tool in our project. This tool has its own language which is similar to Java. I am looking for a static analysis tool which can be applied to the new language. Are there any static analysis tools which can be customized to any languages? or Is there any document or any reference on how to develop the static analysis tool for our own languages? Thanks.

    Read the article

  • Is it safe to lock a static variable in a non-static class?

    - by Dario Solera
    I've got a class that manages a shared resource. Now, since access to the resource depends on many parameters, this class is instantiated and disposed several times during the normal execution of the program. The shared resource does not support concurrency, so some kind of locking is needed. The first thing that came into my mind is having a static instance in the class, and acquire locks on it, like this: // This thing is static! static readonly object MyLock = new object(); // This thing is NOT static! MyResource _resource = ...; public DoSomeWork() { lock(MyLock) { _resource.Access(); } } Does that make sense, or would you use another approach?

    Read the article

  • Objective-C categories in static library

    - by Vladimir
    Can you guide me how to properly link static library to iphone project. I use staic library project added to app project as direct dependency (target - general - direct dependecies) and all works OK, but categories. A category defined in static library is not working in app. So my question is how to add static library with some categories into other project? And in general, what is best practice to use in app project code from other projects?

    Read the article

  • Why can't I inherit static classes?

    - by User
    I have several classes that do not really need any state. From the organizational point of view, I would like to put them into hierarchy. But it seems I can't declare inheritance for static classes. Something like that: public static class Base { } public static class Inherited : Base { } will not work. Why have the designers of the language closed that possibility?

    Read the article

  • Passing data to a non-static listBox, by calling function from another class

    - by Andrew A
    I have a simple forms program that I have been fighting with for a while now. I simply want to be able to call a method from a different class file (when a certain step is triggered in the code in that class file) in order to insert a string in the listBox. Here is my main method, pretty standard: class Program { [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } Here is the function which resides in my MainForm.cs file, which I can call just fine from that class file (via 'TextToBox(myString);'): public partial class MainForm : Form { ... // Function to output results to main Listbox window public void TextToBox(string aString) { // Place messages in Main Display list box window this.listBox1.Items.Insert(0, aString); } ... } But my problem is when I am in another class and I want to call 'TextToBox(myString);'. If I create another object reference of the MainForm, the code compiles fine but nothing will show up in the listBox. How do I do this? I cannot simply make TextToBox() static. I know I must create the object reference but I can't figure out how to reference the ORIGINAL MainForm, the one that was created in the Main method. Thanks in advance...

    Read the article

  • Linking error while using Qt static built libraries

    - by Kamran Amini
    I hope this is not a duplicate. Recently I'm developing a native C++ application using Qt 4.8.3 and VS2008. Since clients run the application on their naked machines, they need to install VC++ 2008 Redistribution package. So I decided to make it statically linked. I changed my project settings (C/C++ Code Generation Runtime Library) to /MTd. Also I compiled Qt again, this time using following commands for a static building; originally found on this blog Static Qt with static CRT (VS 2008) 1- replaced -MD with -MT in lines QMAKE_CFLAGS_RELEASE and QMAKE_CFLAGS_DEBUG in %QDIR%\mkspecs\win32-msvc2008\qmake.conf 2- nmake confclean 3- configure -static -platform win32-msvc2008 -no-webkit 4- nmake sub-src I compiled Qt successfully. But when I tried again to compile my application, it gave me some strange errors. 1>Linking... 1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: bool __thiscall QBasicAtomicInt::deref(void)" (?deref@QBasicAtomicInt@@QAE_NXZ) already defined in QtCored4.lib(QtCored4.dll) 1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: bool __thiscall QBasicAtomicInt::operator!=(int)const " (??9QBasicAtomicInt@@QBE_NH@Z) already defined in QtCored4.lib(QtCored4.dll) 1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: __thiscall QString::~QString(void)" (??1QString@@QAE@XZ) already defined in QtCored4.lib(QtCored4.dll) I changed some lib files but with each change, situation got worse; for example I tried to use QtCored.lib instead of QtCored4.lib because it is newly created after compilation. I think I've missed something in building static Qt libs. Thanks.

    Read the article

  • Static variables in Java for a test oObject creator

    - by stevebot
    Hey, I have something like the following TestObjectCreator{ private static Person person; private static Company company; static { person = new Person() person.setName("Joe"); company = new Company(); company.setName("Apple"); } public Person createTestPerson(){ return person; } public Person createTestCompany(){ return company; } } By applying static{} what am I gaining? I assume the objects are singletons as a result. However, if I did the following: Person person = TestObjectCreator.createTestPerson(); person.setName("Jill"); Person person2 = TestObjectCreator.createTestPerson(); would person2 be named Jill or Joe?

    Read the article

  • Obj-c categories in static library

    - by Vladimir
    Can you guide me how to properly link static library to iphone project. I use staic library project added to app project as direct dependency (target - general - direct dependecies) and all works OK, but categories. A category defined in static library is not working in app. So my question is how to add static library with some categories into other project? And in general, what is best practice to use in app project code from other projects?

    Read the article

  • How to return Current Object in a Static function in PHP

    - by streetparade
    I neet access to current object in a static method. Code: protected static $name; public static function name($modulename) { self::$name = $modulename; } public function __call($name, $arguments) { $me = new test(self::$name); return $me->$name($arguments); } I want to be able to call method log in Log class. Like this echo Mods::name("Log")->log("test"); How do i do that?

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >