Search Results

Search found 9718 results on 389 pages for 'classes'.

Page 12/389 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • "Public" nested classes or not

    - by Frederick
    Suppose I have a class 'Application'. In order to be initialised it takes certain settings in the constructor. Let's also assume that the number of settings is so many that it's compelling to place them in a class of their own. Compare the following two implementations of this scenario. Implementation 1: class Application { Application(ApplicationSettings settings) { //Do initialisation here } } class ApplicationSettings { //Settings related methods and properties here } Implementation 2: class Application { Application(Application.Settings settings) { //Do initialisation here } class Settings { //Settings related methods and properties here } } To me, the second approach is very much preferable. It is more readable because it strongly emphasises the relation between the two classes. When I write code to instantiate Application class anywhere, the second approach is going to look prettier. Now just imagine the Settings class itself in turn had some similarly "related" class and that class in turn did so too. Go only three such levels and the class naming gets out out of hand in the 'non-nested' case. If you nest, however, things still stay elegant. Despite the above, I've read people saying on StackOverflow that nested classes are justified only if they're not visible to the outside world; that is if they are used only for the internal implementation of the containing class. The commonly cited objection is bloating the size of containing class's source file, but partial classes is the perfect solution for that problem. My question is, why are we wary of the "publicly exposed" use of nested classes? Are there any other arguments against such use?

    Read the article

  • Immutable classes in C++

    - by ereOn
    Hi, In one of my projects, I have some classes that represent entities that cannot change once created, aka. immutable classes. Example : A class RSAKey that represent a RSA key which only has const methods. There is no point changing the existing instance: if you need another one, you just create one. My objects sometimes are heavy and I enforced the use of smart pointers to avoid copy. So far, I have the following pattern for my classes: class RSAKey : public boost::noncopyable, public boost::enable_shared_from_this<RSAKey> { public: /** * \brief Some factory. * \param member A member value. * \return An instance. */ static boost::shared_ptr<const RSAKey> createFromMember(int member); /** * \brief Get a member. * \return The member. */ int getMember() const; private: /** * \brief Constructor. * \param member A member. */ RSAKey(int member); /** * \brief Member. */ const int m_member; }; So you can only get a pointer (well, a smart pointer) to a const RSAKey. To me, it makes sense, because having a non-const reference to the instance is useless (it only has const methods). Do you guys see any issue regarding this pattern ? Are immutable classes something common in C++ or did I just created a monster ? Thank you for your advices !

    Read the article

  • Add webservice reference, the classes in different file

    - by ArunDhaJ
    Hi, When I add webservice as service reference in my .Net project, it creates a service folder within "Service References". All the interfaces and classes are contained within that service folder. I wanted to know how to split the interface's method and classes. Actually I wanted the web service reference to import classes defined in different dll. I wanted to define this way because of my design constraints. I've 3 layered application. Of which third layer is communication layer which holds all web service references. second is business layer and first is presentation layer. If the class declarations are in layer-3 and I'm accessing those classes from presentation layer, it is logically a cross-layer-access-violation. Instead, I wanted a separate project which holds only the class declarations and this would be used in all 3 layers. I didn't faced any problems to achieve this with layer-1 and layer-2. But, I'm not sure how to make communication layer to use this common declaration dll. Your suggestion would help me to design my application better. Thanks in advance Regards ArunDhaJ

    Read the article

  • Partial Classes - are they bad design?

    - by dferraro
    Hello, I'm wondering why the 'partial class' concept even exists in .NET. I'm working on an application and we are reading a (actually very good) book relavant to the development platform we are implementing at work. In the book he provides a large code base /wrapper around the platform API and explains how he developed it as he teaches different topics about the platform development. Anyway, long story short - he uses partial classes, all over the place, as a way to fake multiple inheritence in C# (IMO). Why he didnt just split the classes up into multiple ones and use composition is beyond me. He will have 3 'partial class' files to make up his base class, each w/ 3-500 lines of code... And does this several times in his API. Do you find this justifiable? If it were me, I'd have followed the S.R.P. and created multiple classes to handle different required behaviors, then create a base class that has instances of these classes as members (e.g. composition). Why did MS even put partial class into the framework?? They removed the ability to expand/collapse all code at each scope level in C# (this was allowed in C++) because it was obviously just allowing bad habits - partial class is IMO the same thing. I guess my quetion is: Can you explain to me when there would be a legitimate reason to ever use a partial class? I do not mean this to be a rant / war thread. I'm honeslty looking to learn something here. Thanks

    Read the article

  • How to control dojo widget classes, or how to get fine-grained control of style

    - by djna
    I am creating a UI with dojo that is emulting some aspects of an existing thick client application. I need to programatically put two different menu bars on the same page. I have successfully created the two menu bars using new dijit.Menu(); new dijit.MenuItem(); and so on. Now I want to give them slightly different presentation styles. As I'm going to have quite a few pages of this sort my first thought is to use different CSS style classes. And that's the problem: when I create the Menu and it's items we get quite a set of HTML objects, each with CSS classes specified by dojo, and the classes are the same for the items associated with either menu. How can I best get specific control for any one menu? I could determine the dojo-generated ids for each item, and specify styles by ids, but that seems like hard work. Is there an sensible way to control the classes defined by dojo, or a nice CSS way to select only the items associated with one menu bar?

    Read the article

  • how do I best create a set of list classes to match my business objects

    - by ken-forslund
    I'm a bit fuzzy on the best way to solve the problem of needing a list for each of my business objects that implements some overridden functions. Here's the setup: I have a baseObject that sets up database, and has its proper Dispose() method All my other business objects inherit from it, and if necessary, override Dispose() Some of these classes also contain arrays (lists) of other objects. So I create a class that holds a List of these. I'm aware I could just use the generic List, but that doesn't let me add extra features like Dispose() so it will loop through and clean up. So if I had objects called User, Project and Schedule, I would create UserList, ProjectList, ScheduleList. In the past, I have simply had these inherit from List< with the appropriate class named and then written the pile of common functions I wanted it to have, like Dispose(). this meant I would verify by hand, that each of these List classes had the same set of methods. Some of these classes had pretty simple versions of these methods that could have been inherited from a base list class. I could write an interface, to force me to ensure that each of my List classes has the same functions, but interfaces don't let me write common base functions that SOME of the lists might override. I had tried to write a baseObjectList that inherited from List, and then make my other Lists inherit from that, but there are issues with that (which is really why I came here). One of which was trying to use the Find() method with a predicate. I've simplified the problem down to just a discussion of Dispose() method on the list that loops through and disposes its contents, but in reality, I have several other common functions that I want all my lists to have. What's the best practice to solve this organizational matter?

    Read the article

  • Issue with class design to model user preferences for different classes

    - by Mulone
    Hi all, I'm not sure how to design a couple of classes in my app. Basically that's a situation: each user can have many preferences each preference can be referred to an object of different classes (e.g. album, film, book etc) the preference is expressed as a set of values (e.g. score, etc). The problem is that many users can have preferences on the same objects, e.g.: John: score=5 for filmid=apocalypsenow Paul: score=3 for filmid=apocalypsenow And naturally I don't want to duplicate the object film in each user. So I could create a class called "preference" holding a score and then a target object, something like: User{ hasMany preferences } Preference{ belongsTo User double score Film target Album target //etc } and then define just one target. Then I would create an interface for the target Classes (album, film etc): Interface canBePreferred{ hasMany preferences } And implement all of those classes. This could work, but it looks pretty ugly and it would requires a lot of joins to work. Do you have some patterns I could use to model this nicely? Cheers, Mulone

    Read the article

  • class modifier issues in C# with "private" classes

    - by devoured elysium
    I had a class that had lots of methods: public class MyClass { public bool checkConditions() { return checkCondition1() && checkCondition2() && checkCondition3(); } ...conditions methods public void DoProcess() { FirstPartOfProcess(); SecondPartOfProcess(); ThirdPartOfProcess(); } ...process methods } I identified two "vital" work areas, and decided to extract those methods to classes of its own: public class MyClass { private readonly MyClassConditions _conditions = new ...; private readonly MyClassProcessExecution = new ...; public bool checkConditions() { return _conditions.checkConditions(); } public void DoProcess() { _process.DoProcess(); } } In Java, I'd define MyClassConditions and MyClassProcessExecution as package protected, but I can't do that in C#. How would you go about doing this in C#? Setting both classes as inner classes of MyClass? I have 2 options: I either define them inside MyClass, having everything in the same file, which looks confusing and ugly, or I can define MyClass as a partial class, having one file for MyClass, other for MyClassConditions and other for MyClassProcessExecution. Defining them as internal? I don't really like that much of the internal modifier, as I don't find these classes add any value at all for the rest of my program/assembly, and I'd like to hide them if possible. It's not like they're gonna be useful/reusable in any other part of the program. Keep them as public? I can't see why, but I've let this option here. Any other? Name it! Thanks

    Read the article

  • Passing System classes as constructor parameters

    - by mcl
    This is probably crazy. I want to take the idea of Dependency Injection to extremes. I have isolated all System.IO-related behavior into a single class so that I can mock that class in my other classes and thereby relieve my larger suite of unit tests of the burden of worrying about the actual file system. But the File IO class I end up with can only be tested with integration tests, which-- of course-- introduces complexity I don't really want to deal with when all I really want to do is make sure my FileIO class calls the correct System.IO stuff. I don't need to integration test System.IO. My FileIO class is doing more than simply wrapping System.IO functions, every now and then it does contain some logic (maybe this is the problem?). So what I'd like is to be able to test my File IO class to ensure that it makes the correct system calls by mocking the System.IO classes themselves. Ideally this would be as easy as having a constructor like so: public FileIO( System.IO.Directory directory, System.IO.File file, System.IO.FileStream fileStream ) { this.Directory = directory; this.File = file; this.FileStream = fileStream; } And then calling in methods like: public GetFilesInFolder(string folderPath) { return this.Directory.GetFiles(folderPath) } But this doesn't fly since the System.IO classes in question are static classes. As far as I can tell they can neither be instantiated in this way or subclassed for the purposes of mocking.

    Read the article

  • Unsure how to come up with a good design

    - by Mewzer
    Hello there, I am having trouble coming up with a good design for a group of classes and was hoping that someone could give me some guidance on best practices. I have kept the classes and member functions generic to make the problem simpler. Essentially, I have three classes (lets call them A, B, and C) as follows: class A { ... int GetX( void ) const { return x; }; int GetY( void ) const { return y; }; private: B b; // NOTE: A "has-a" B int x; int y; }; class B { ... void SetZ( int value ) { z = value }; private: int z; C c; // NOTE: B "has-a" C }; class C { private: ... void DoSomething(int x, int y){ ... }; void DoSomethingElse( int z ){ ... }; }; My problem is as follows: Class A uses its member variables "x" and "y" a lot internally. Class B uses its member variable "z" a lot internally. Class B needs to call C::DoSomething(), but C::DoSomething() needs the values of X and Y in class A passed in as arguments. C::DoSomethingElse() is called from say another class (e.g. D), but it needs to invoke SetZ() in class B!. As you can see, it is a bit of a mess as all the classes need information from one another!. Are there any design patterns I can use?. Any ideas would be much appreciated ....

    Read the article

  • Reuse classes and objects for both WCF and non-WCF

    - by joebeazelman
    I have several classes such as Order, Customer, etc. These classes serve for holding data and nothing more. I want to be able to reuse these classes in other projects in the future, but for some reason I don't quite understand, WCF forces me to decorate the data members with the [DataMember] attribute, forcing me to reference WCF plumbing that I will never use in other projects. I would imagine that WCF lets you take any serializable class and use it as a content type. Am I understanding this correctly?

    Read the article

  • How to list all (groovy) classes in JVM in groovy

    - by Dan
    I am writing a DelegatingMetaClass that I would like to apply to all groovy classes in my project, but I do not how to get hold of all classes in the project? Here is the code: /* This will work ok, since I know Foo beforehand, but what about classes that do not exist yet? */ def myMetaClass = new DelegatingMetaClass(Foo.class) InvokerHelper.metaRegistry.setMetaClass(Foo.class, myMetaClass) /* how to do this? allGroovyClasses.each{ def myMetaClass = new DelegatingMetaClass(it) InvokerHelper.metaRegistry.setMetaClass(it, myMetaClass) } */ class SimpleInterceptor extends DelegatingMetaClass{ public SimpleInterceptor(final Class aclass) { super(aclass); initialize(); } public Object getProperty(Object object, String prop) { println ("I am in a property interceptor!!!") return super.getProperty(object, prop) } public Object invokeMethod(Object a_object, String a_methodName, Object[] a_arguments) { println ("I am in a method interceptor!!!") return super.invokeMethod(a_object, a_methodName, a_arguments) }

    Read the article

  • Sharing classes between projects in xcode/objective-c

    - by Allyn
    Hey folks, I've got a client<=server app I'm building for Mac OS X, using Objective-c/Cocoa and xCode. I've created a different project for both the apps I have, and I'm wondering the best way to share classes between them. There are several classes I've made that would be useful to both. This far I've been copying them around, but I feel like this isn't the best solution. How do I share classes effectively? Should I redo it as 1 project and just have two build targets? How do I do this? Any other info? Thanks.

    Read the article

  • Importing Swift classes within a Objective-C Framework

    - by theMonster
    I have a custom Framework that has a bunch of Objective-C Classes. Within the Framework, I'd like to add more classes using Swift. However, when trying to expose the Swift classes to the Objective-C code using: MyProduct-Swift.h, it comes up as "MyProduct-Swift.h file not found". I've tried this in a single view template and it works fine. Is it not possible to import Swift within a framework? I've also verified that I have set the Defines Module setting and the Module Name. I've tried it with and without these settings.

    Read the article

  • Best practice Unit testing abstract classes?

    - by Paul Whelan
    Hello I was wondering what the best practice is for unit testing abstract classes and classes that extend abstract classes. Should I test the abstract class by extending it and stubbing out the abstract methods and then test all the concrete methods? Then only test the methods I override and the abstract methods in the unit tests for objects that extend my abstract class. Should I have an abstract test case that can be used to test the methods of the abstract class and extend this class in my test case for objects that extend the abstract class? EDIT: My abstract class has some concrete methods. I would be interested to see what people are using. Thanks Paul

    Read the article

  • How to generate Doctrine models/classes that extend a custom record class

    - by Shane O'Grady
    When I use Doctrine to generate classes from Yaml/db each Base class (which includes the table definition) extends the Doctrine_Record class. Since my app uses a master and (multiple) slave db servers I need to be able to make the Base classes extend my custom record class to force writes to go to the master db server (as described here). However if I change the base class manually I lose it again when I regenerate my classes from Yaml/db using Doctrine. I need to find a way of telling Doctrine to extend my own Base class, or find a different solution to a master/slave db setup using Doctrine. Example generated model: abstract class My_Base_User extends Doctrine_Record { However I need it to be automatically generated as: abstract class My_Base_User extends My_Record { I am using Doctrine 1.2.1 in a new Zend Framework 1.9.6 application if it makes any difference.

    Read the article

  • Naming convention for utility classes in Java

    - by Zarjay
    When writing utility classes in Java, what are some good guidelines to follow? Should packges be "util" or "utils"? Is it ClassUtil or ClassUtils? When is a class a "Helper" or a "Utility"? Utility or Utilities? Or do you use a mixture of them? The standard Java library uses both Utils and Utilities: javax.swing.Utilities javax.print.attribute.AttributeSetUtilities javax.swing.plaf.basic.BasicGraphicsUtils Apache uses a variety of Util and Utils, although mostly Utils: org.apache.commons.modeler.util.DomUtil org.apache.commons.modeler.util.IntrospectionUtils org.apache.commons.io.FileSystemUtils org.apache.lucene.wordnet.AnalyzerUtil org.apache.lucene.util.ArrayUtil org.apache.lucene.xmlparser.DOMUtils Spring uses a lot of Helper and Utils classes: org.springframework.web.util.UrlPathHelper org.springframework.core.ReflectiveVisitorHelper org.springframework.core.NestedExceptionUtils org.springframework.util.NumberUtils So, how do you name your utility classes?

    Read the article

  • Referencing external classes

    - by moppel
    My Android project references external classfiles that are not included in the in the Android SDK. I added those classes as an external library properly in eclipse. The code compiles with no problem. But as I try to run the application I get an ClassNotFoundException by the DalvikVM, although all the neccessary classes have been ported. Am I missing something? The steps I did. create new folder in eclipse android project. copy neccessary classes in this folder. add the folder to the classpath via eclipse. programm compile run as android application -- Exception

    Read the article

  • Exposing classes inside modules within a Python package directly in the package's namespace

    - by Richard Waite
    I have a wxPython application with the various GUI classes in their own modules in a package called gui. With this setup, importing the main window would be done as follows: from gui.mainwindow import MainWindow This looked messy to me so I changed the __init__.py file for the gui package to import the class directly into the package namespace: from mainwindow import MainWindow This allows me to import the main window like this: from gui import MainWindow This looks better to me aesthetically and I think it also more closely represents what I'm doing (importing the MainWindow class from the gui "namespace"). The reason I made the gui package was to keep all the GUI stuff together. I could have just as easily made a single gui module and stuffed all the GUI classes in it, but I think that would have been unmanageable. The package now appears to work like a module, but allows me to separate the classes into their own modules (along with helper functions, etc.). This whole thing strikes me as somewhat petty, I just thought I'd throw it out there to see what others think about the idea.

    Read the article

  • Extracting an interface from .NEt System classes

    - by Thomas
    When using Visual Studio it is easy to extract an interface from a class that I have written myself. I right click on the class and select 'Refactor' then select 'Extract Interface'. Let's assume for a second that I wanted to create a ConfigurationManager wrapper and write some tests around it. A quick way to do that would be to extract an interface from ConfigurationManager by right clicking it, then 'Go To Definition' and then from inside the class select 'Refactor' then select 'Extract Interface'. Then I would simply create my wrapper class, inherit from my newly created interface, and then implement it and I have a great starting point for my wrapper class. However, extracting an interface from any .NET system classes is not possible, probably because it's just meta data about the classes and not the classes themselves (or I am doing it wrong). Is there an easy way to do what I am trying to accomplish? I want to ensure I am not wasting time typing what I don't need to be typing. Thanks

    Read the article

  • Help Me Understand C++ Header files and Classes

    - by JamesW
    OK, So I am trying to transition from intermediate Delphi to C++ Object Oriented programing. I have read Ivar Horton's book on visual C++ 2010. I can pull off the simple console applications no problem. I get the language itself (kinda). Where I am struggling is with headers and classes. I also understand what header files and classes do in general. What I am not getting is the implementation when do I use a header or a class? Do I need to create classes for everything I do? Do my actual work functions need to be in header files or in CPP files? I'm lost on the proper uses of these and could use some real world guidance from more experienced programmers. I am trying to transition to windows applications using the MFC if that is helpful.

    Read the article

  • Incompatible classes when loading SWF

    - by Bart van Heukelom
    I have two ActionScript 3 projects, game(.swf) and minigame(.swf). At runtime the main game loads the minigame via Loader. I also have a shared library (SWC) of event classes, included by both, which minigame will need to dispatch and game will need to listen to. First: Is this possible this way? Second: What will happen if I compile the minigame, then change the event classes so they're incompatible, then compile the main game. Will Flash crash when trying to load the minigame SWF? (I hope so) Third: And what will happen if I change the event classes, but in a way that preserves interface-level compatibility?

    Read the article

  • Importing Classes Within a Module

    - by CodeJoust
    Currently, I have a parser with multiple classes that work together. For Instance: TreeParser creates multiple Product and Reactant modules which in turn create multiple Element classes. The TreeParser is called by a render method within the same module, which is called from the importer. Currently, using the class name in the imported module file works only if the file calling the module contains from module_name import *, so the classes are imported into the main namespace. Finally, if the package has dependencies (such as re and another another module within the same folder), where is the best place to require those modules? Within the __init__.py file or within the module itself? I don't really want to add the module name in front of every call to the class, in case I do call import *, however, is it possible to use a variable name of the current module to call the class, or use a workaround in the __init__.py file? I'm probably used to the ruby require '' method instead of python's module system.

    Read the article

  • Strange Java Coding??? Class in class???

    - by poeschlorn
    Hi guys, I got a question about Java coding in general... In some sample codes there are methods and classes declared WITHIN other methods and/or classes.... I've never heard/red about this...what effect does this kind of programming have? Wouldn't it be better to write down classes in a seperate file and methods side by side and not within each other (like every book tells you)? What are the advantages and disadvantages of this kind of programming? Here's an example of what I mean: Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { TextView textView = (TextView) findViewById(R.id.description); textView.setText(mRoad.mName + " " + mRoad.mDescription); MapOverlay mapOverlay = new MapOverlay(mRoad, mapView); List<Overlay> listOfOverlays = mapView.getOverlays(); listOfOverlays.clear(); listOfOverlays.add(mapOverlay); mapView.invalidate(); }; };

    Read the article

  • Opinions sought on the best way to organise classes in PHP

    - by jax
    I am pretty much set on using the Java package naming convention of com.website.app.whatever but am unsure about the best way of doing this in PHP. Option 1: Create a directory structure com/ mysite/ myapp/ encryption/ PublicKeyGenerator.class.php Cipher.class.php Xml/ XmlHelper.class.php XmlResponse.class.php Now this is how Java does it, it uses the folders to organize the heirarchy. This is however a little clumsy in PHP because there is no native support for it and when you move things around you break all includes. Option 2 Name classes using a periods for the package, therefore sames are just like in Java but can all be in the same directory making __autoload a breeze. classes/ com.mysite.myapp.encription.PublicKeyGenerator.class.php com.mysite.myapp.encription.Cipher.class.php com.mysite.myapp.xml.XmlHelper.class.php com.mysite.myapp.xml.XmlResponse.class.php The only real disadvantage here is that all the classes are in a single folder which might be confusing for large projects. Opinions sought, which is the best or are there other even better options?

    Read the article

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