Search Results

Search found 45620 results on 1825 pages for 'derived class'.

Page 3/1825 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Naming a class that processes orders

    - by p.campbell
    I'm in the midst of refactoring a project. I've recently read Clean Code, and want to heed some of the advice within, with particular interest in Single Responsibility Principle (SRP). Currently, there's a class called OrderProcessor in the context of a manufacturing product order system. This class is currently performs the following routine every n minutes: check database for newly submitted + unprocessed orders (via a Data Layer class already, phew!) gather all the details of the orders mark them as in-process iterate through each to: perform some integrity checking call a web service on a 3rd party system to place the order check status return value of the web service for success/fail email somebody if web service returns fail constantly log to a text file on each operation or possible fail point I've started by breaking out this class into new classes like: OrderService - poor name. This is the one that wakes up every n minutes OrderGatherer - calls the DL to get the order from the database OrderIterator (? seems too forced or poorly named) - OrderPlacer - calls web service to place the order EmailSender Logger I'm struggling to find good names for each class, and implementing SRP in a reasonable way. How could this class be separated into new class with discrete responsibilities?

    Read the article

  • Calling base class constructor

    - by The Void
    In the program below, is the line Derived(double y): Base(), y_(y) correct/allowed? That is, does it follow ANSI rules? #include <iostream> class Base { public: Base(): x_(0) { std::cout << "Base default constructor called" << std::endl; } Base(int x): x_(x) { std::cout << "Base constructor called with x = " << x << std::endl; } void display() const { std::cout << x_ << std::endl; } protected: int x_; }; class Derived: public Base { public: Derived(): Base(1), y_(1.2) { std::cout << "Derived default constructor called" << std::endl; } Derived(double y): Base(), y_(y) { std::cout << "Derived constructor called with y = " << y << std::endl; } void display() const { std::cout << Base::x_ << ", " << y_ << std::endl; } private: double y_; }; int main() { Base b1; b1.display(); Derived d1; d1.display(); std::cout << std::endl; Base b2(-9); b2.display(); Derived d2(-8.7); d2.display(); return 0; }

    Read the article

  • Pointing class property to another class with vectors

    - by jmclem
    I've got a simple class, and another class that has a property that points to the first class: #include <iostream> #include <vector> using namespace std; class first{ public: int var1; }; class second{ public: first* classvar; }; Then, i've got a void that's supposed to point "classvar" to the intended iteration of the class "first". void fill(vector<second>& sec, vector<first>& fir){ sec[0].classvar = &fir[0]; } Finally the main(). Create and fill a vector of class "first", create "second" vector, and run the fill function. int main(){ vector<first> a(1); a[0].var1 = 1000; vector<second> b(1); fill(b, a); cout << b[0].classvar.var1 << '\n'; system("PAUSE"); return 0; } This gives me the following error: 1>c:\...\main.cpp(29) : error C2228: left of '.var1' must have class/struct/union 1> type is 'first *' And I can't figure out why it reads the "classvar" as the whole vector instead of just the single instance. Should I do this cout << b[0].classvar[0].var1 << '\n'; it reads perfectly. Can anyone figure out the problem? Thanks in advance

    Read the article

  • Subquery using derived table in Hibernate HQL

    - by Vladimir
    I have a Hibernate HQL question. I'd like to write a subquery as a derived table (for performance reasons). Is it possible to do that in HQL? Example: FROM Customer WHERE country.id in (SELECT id FROM (SELECT id FROM Country where type='GREEN') derivedTable) (btw, this is just a sample query so don't give advices on rewriting it, is just the derived table concept I'm interested in) Thanks.

    Read the article

  • Hide a base class method from derived class, but still visible outside of assembly

    - by clintp
    This is a question about tidyness. The project is already working, I'm satisfied with the design but I have a couple of loose ends that I'd like to tie up. My project has a plugin architecture. The main body of the program dispatches work to the plugins that each reside in their own AppDomain. The plugins are described with an interface, which is used by the main program (to get the signature for invoking DispatchTaskToPlugin) and by the plugins themselves as an API contract: namespace AppServer.Plugin.Common { public interface IAppServerPlugin { void Register(); void DispatchTaskToPlugin(Task t); // Other methods omitted } } In the main body of the program Register() is called so that the plugin can register its callback methods with the base class, and then later DispatchTaskToPlugin() is called to get the plugin running. The plugins themselves are in two parts. There's a base class that implements the framework for the plugin (setup, housekeeping, teardown, etc..). This is where DispatchTaskToPlugin is actually defined: namespace AppServer.Plugin { abstract public class BasePlugin : MarshalByRefObject, AppServer.Plugin.Common.IAppServerPlugin { public void DispatchTaskToPlugin(Task t) { // ... // Eventual call to actual plugin code // } // Other methods omitted } } The actual plugins themselves only need to implement a Register() method (to give the base class the delegates to call eventually) and then their business logic. namespace AppServer.Plugin { public class Plugin : BasePlugin { override public void Register() { // Calls a method in the base class to register itself. } // Various callback methods, business logic, etc... } } Now in the base class (BasePlugin) I've implemented all kinds of convenience methods, collected data, etc.. for the plugins to use. Everything's kosher except for that lingering method DispatchTaskToPlugin(). It's not supposed to be callable from the Plugin class implementations -- they have no use for it. It's only needed by the dispatcher in the main body of the program. How can I prevent the derived classes (Plugin) from seeing the method in the base class (BasePlugin/DispatchTaskToPlugin) but still have it visible from outside of the assembly? I can split hairs and have DispatchTaskToPlugin() throw an exception if it's called from the derived classes, but that's closing the barn door a little late. I'd like to keep it out of Intellisense or possibly have the compiler take care of this for me. Suggestions?

    Read the article

  • polymorphism, inheritance in c# - base class calling overridden method?

    - by Andrew Johns
    This code doesn't work, but hopefully you'll get what I'm trying to achieve here. I've got a Money class, which I've taken from http://www.noticeablydifferent.com/CodeSamples/Money.aspx, and extended it a little to include currency conversion. The implementation for the actual conversion rate could be different in each project, so I decided to move the actual method for retrieving a conversion rate (GetCurrencyConversionRate) into a derived class, but the ConvertTo method contains code that would work for any implementation assuming the derived class has overriden GetCurrencyConversionRate so it made sense to me to keep it in the parent class? So what I'm trying to do is get an instance of SubMoney, and be able to call the .ConvertTo() method, which would in turn use the overriden GetCurrencyConversionRate, and return a new instance of SubMoney. The problem is, I'm not really understanding some concepts of polymorphism and inheritance yet, so not quite sure what I'm trying to do is even possible in the way I think it is, as what is currently happening is that I end up with an Exception where it has used the base GetCurrencyConversionRate method instead of the derived one. Something tells me I need to move the ConvertTo method down to the derived class, but this seems like I'll be duplicating code in multiple implementations, so surely there's a better way? public class Money { public CurrencyConversionRate { get { return GetCurrencyConversionRate(_regionInfo.ISOCurrencySymbol); } } public static decimal GetCurrencyConversionRate(string isoCurrencySymbol) { throw new Exception("Must override this method if you wish to use it."); } public Money ConvertTo(string cultureName) { // convert to base USD first by dividing current amount by it's exchange rate. Money someMoney = this; decimal conversionRate = this.CurrencyConversionRate; decimal convertedUSDAmount = Money.Divide(someMoney, conversionRate).Amount; // now convert to new currency CultureInfo cultureInfo = new CultureInfo(cultureName); RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID); conversionRate = GetCurrencyConversionRate(regionInfo.ISOCurrencySymbol); decimal convertedAmount = convertedUSDAmount * conversionRate; Money convertedMoney = new Money(convertedAmount, cultureName); return convertedMoney; } } public class SubMoney { public SubMoney(decimal amount, string cultureName) : base(amount, cultureName) {} public static new decimal GetCurrencyConversionRate(string isoCurrencySymbol) { // This would get the conversion rate from some web or database source decimal result = new Decimal(2); return result; } }

    Read the article

  • Using a class within another class in asp.net

    - by Phil
    In my site I have class A which selects the required page module (blog,content,gallery etc). I also have class B which provides sqlclient database objects and sql statements. If I use class B in a web form via "Imports Class B". I am able to access the contents. I now would like to use class B within class A but am struggling to find the correct syntax for importing it. Please can someone give me a basic example. We are coming from a classic asp background, and used to simply use includes. We are using VB Thanks.

    Read the article

  • Dynamic loading a class in java with a different package name

    - by C. Ross
    Is it possible to load a class in Java and 'fake' the package name/canonical name of a class? I tried doing this, the obvious way, but I get a "class name doesn't match" message in a ClassDefNotFoundException. The reason I'm doing this is I'm trying to load an API that was written in the default package so that I can use it directly without using reflection. The code will compile against the class in a folder structure representing the package and a package name import. ie: ./com/DefaultPackageClass.class // ... import com.DefaultPackageClass; import java.util.Vector; // ... My current code is as follows: public Class loadClass(String name) throws ClassNotFoundException { if(!CLASS_NAME.equals(name)) return super.loadClass(name); try { URL myUrl = new URL(fileUrl); URLConnection connection = myUrl.openConnection(); InputStream input = connection.getInputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int data = input.read(); while(data != -1){ buffer.write(data); data = input.read(); } input.close(); byte[] classData = buffer.toByteArray(); return defineClass(CLASS_NAME, classData, 0, classData.length); } catch (MalformedURLException e) { throw new UndeclaredThrowableException(e); } catch (IOException e) { throw new UndeclaredThrowableException(e); } }

    Read the article

  • making class accessible from class path in dynamic class loading

    - by Noona
    I have a project created in Eclipse, and I defined an interface and a class for dynamic class loading, the class is in the project directory, so I have this code in my project: if (handlerClassName != null) { TypeHandler typeHandler = null; try { typeHandler = (TypeHandler) (Class.forName(handlerClassName).newInstance()); but I get this exception: java.lang.ClassNotFoundException: "handlerClassName" what should I do to make the JVM recognize the class "handlerClassName" in my project? thanks

    Read the article

  • Question about casting a class in Java with generics

    - by Florian F
    In Java 6 Class<? extends ArrayList<?>> a = ArrayList.class; gives and error, but Class<? extends ArrayList<?>> b = (Class<? extends ArrayList<?>>)ArrayList.class; gives a warning. Why is (a) an error? What is it, that Java needs to do in the assignment, if not the cast shown in (b)? And why isn't ArrayList compatible with ArrayList? I know one is "raw" and the other is "generic", but what is it you can do with an ArrayList and not with an ArrayList, or the other way around?

    Read the article

  • Java code generation from class diagram

    - by Sanjay
    I'm on the way developing a Java application where user can provide a class diagram and get the corresponding Java code. I don't know how can I let the user interactively draw a class diagram in Java. I am currently getting the required parameters like attributes, functions directly from the user, and then I render a class diagram for him. I show the class diagram on a jdialog. Is there a better way to do this? This is an example of a class diagram, I need to generate this from a Java program, given the values and relationship.

    Read the article

  • Switching from abstract class to interface

    - by nischayn22
    I have an abstract class which has all abstract methods except one which constructs objects of the subclasses. Now my mentor asked me to move this abstract class to an interface. Having an interface is no problem except with the method used to construct subclass objects. Where should this method go now? Also, I read somewhere that interfaces are more efficient than abstract classes. Is this true? Here's an example of my classes abstract class Animal { //many abstract methods getAnimalobject(some parameter) { return //appropriate subclass } } class Dog extends Animal {} class Elephant extends Animal {}

    Read the article

  • C# Cast Class to Overridden Class

    - by Nathan Tornquist
    I have a class Application that I need to override with INotifyPropertyChanged events. I have written the logic to override the original class and ended up creating SuperApplication I am pulling the data from a library though, and cannot change the loading logic. I just need a way to get the data from the original class into my superClass. I've tried things like superClass = (SuperApplication)standardClass; but it hasn't worked. How would I go about doing this? If it helps, this is the code I'm using to override the original class: public class SuperCreditApplication : CreditApplication { public SuperCreditApplicant Applicant { get; set; } public SuperCreditApplicant CoApplicant { get; set; } } public class SuperCreditApplicant : CreditApplicant { public SuperProspect Prospect { get; set; } } public class SuperProspect : Prospect, INotifyPropertyChanged { public State DriverLicenseState { get { return DriverLicenseState; } set { DriverLicenseState = value; OnPropertyChanged("DriverLicenseState"); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }

    Read the article

  • C++ Using a class from a header within a class

    - by Kotsuzui
    I'm having a bit of trouble with classes used within classes, from header files. I have an class time in time.h: class Time { private: int hour, second, minute; public: . . . int getHour(int h); etc. setHour(); etc. void print24hour(); // Prints time in 24 hour format } And then, main.cpp: #include "time.h" class Class { private: string name; double grade; Time startTime; Time endTime; public: Class(); ~Class(); void setName(); void setGrade(); etc. } int main() { //Need to print time in 24 hour format, but I don't know how. class[i].startTime.print24(getStartTime()); // ??? I'm rather lost } I get quite a few "hour, second, minute, etc." are private errors, I'm guessing I'm doing something simple in a rather wrong way. Please help.

    Read the article

  • abstract class extends abstract class in php?

    - by user151841
    I am working on a simple abstract database class. In my usage of this class, I'll want to have some instance be a singleton. I was thinking of having a abstract class that is not a singleton, and then extend it into another abstract class that is a singleton. Is this possible? Recommended?

    Read the article

  • Deriving a class from an abstract class (C++)

    - by cemregoksu
    I have an abstract class with a pure virtual function f() and i want to create a class inherited from that class, and also override function f(). I seperated the header file and the cpp file. I declared the function f(int) in the header file and the definition is in the cpp file. However, the compiler says the derived class is still abstract. How can i fix it?

    Read the article

  • C# vector class - Interpolation design decision

    - by Benjamin
    Currently I'm working on a vector class in C# and now I'm coming to the point, where I've to figure out, how i want to implement the functions for interpolation between two vectors. At first I came up with implementing the functions directly into the vector class... public class Vector3D { public static Vector3D LinearInterpolate(Vector3D vector1, Vector3D vector2, double factor) { ... } public Vector3D LinearInterpolate(Vector3D other, double factor { ... } } (I always offer both: a static method with two vectors as parameters and one non-static, with only one vector as parameter) ...but then I got the idea to use extension methods (defined in a seperate class called "Interpolation" for example), since interpolation isn't really a thing only available for vectors. So this could be another solution: public class Vector3D { ... } public static class Interpolation { public static Vector3D LinearInterpolate(this Vector3D vector, Vector3D other, double factor) { ... } } So here an example how you'd use the different possibilities: { var vec1 = new Vector3D(5, 3, 1); var vec2 = new Vector3D(4, 2, 0); Vector3D vec3; vec3 = vec1.LinearInterpolate(vec2, 0.5); //1 vec3 = Vector3D.LinearInterpolate(vec1, vec2, 0.5); //2 //or with extension-methods vec3 = vec1.LinearInterpolate(vec2, 0.5); //3 (same as 1) vec3 = Interpolation.LinearInterpolation(vec1, vec2, 0.5); //4 } So I really don't know which design is better. Also I don't know if there's an ultimate rule for things like this or if it's just about what someone personally prefers. But I really would like to hear your opinions, what's better (and if possible why ).

    Read the article

  • adhoc struct/class in C#?

    - by acidzombie24
    Currently i am using reflection with sql. I find if i want to make a specialize query it is easiest to get the results by creating a new class inheriting from another and adding the 2 members/columns for my specialized query. Then due to reflections in the lib in my c# code i can write foreach(var v in list) { v.AnyMember and v.MyExtraMember) Now instead of having the class scattered around or modifying my main DB.cs file can i define a class inside a function? I know i can create an anonymous object by writing new {name=val, name2=...}; but i need a to pass this class in a generic function func(query, args);

    Read the article

  • Cannot create class diagram for simple dll class in Visual Studio 2010

    - by xenn_33
    Hi, It seems that there is a really annoying issue in Class Diagram designer in VS (my version is 2010 Ultimate, but the issue is also observed in VS 2008). When I'm trying to create a class diagram for particular simple class from DLL I'm getting the following error: "Some of the selected type(s) cannot be added to the class diagram. Check the code for errors and ensure that all required assemblies ... blah-blah-blah" My code doesn't contain any error. I have multiple class and interface definitions in one separate .cs file, but these classes are really simple - even no calls to unmanaged/interop. Any solution for this?

    Read the article

  • C# new class with only single property : derive from base or encapsulate into new ?

    - by Gobol
    I've tried to be descriptive :) It's rather programming-style problem than coding problem in itself. Let's suppose we have : A: public class MyDict { public Dictionary<int,string> dict; // do custom-serialization of "dict" public void SaveToFile(...); // customized deserialization of "dict" public void LoadFromFile(...); } B: public class MyDict : Dictionary<int,string> { } Which option would be better in the matter of programming style ? class B: is to be de/serialized externally. Main problem is : is it better to create new class (which would have only one property - like opt A:) or to create a new class derived - like opt B: ? I don't want any other data processing than adding/removing and de/serializing to stream. Thanks in advance!

    Read the article

  • jquery: set variable based on one class from an element that has more than one class

    - by John
    Hi I'm trying to make a table who's columns and rows highlight on hover (I realise there are jquery plugins out there that will do this, but I'm trying to learn, so thought I'd have a stab at doing it for myself.) Here's what I've got so far: $('th:not(.features), td:not(.features)').hover(highlight); function highlight(){ $('th.highlightCol, td.highlightCol').removeClass('highlightCol'); var col = $(this).attr('class'); $('.' + col).addClass('highlightCol'); }; $('tr').hover(highlightRowOn, highlightRowOff); function highlightRowOn(){ $(this).children('td:not(.highlightCol)').addClass('highlightRow'); }; function highlightRowOff(){ $(this).children('td:not(.highlightCol)').removeClass('highlightRow'); }; This works fine apart from one problem: Each 'td' has a class specific to it's column (package1, package2, package3, package4). It is this that gets passed to the variable (col) to add the class 'highlightCol' to a column when one of its 'td's are hovered on. However, If you move the cursor to a new column along a highlighted row, the 'td' you land on has two classes (highlightedRow and package* ). These both get passed to the variable and as a result the new column does not receive the correct class to highlight. Is there a way for me to target just the 'package* ' class and pass that to the variable while ignoring the 'highlightedRow' class? I hope that's not too jumbled for someone to make sense of and many thanks for any help offered.

    Read the article

  • Accessing a Class Member from a First-Class Function

    - by dbyrne
    I have a case class which takes a list of functions: case class A(q:Double, r:Double, s:Double, l:List[(Double)=>Double]) I have over 20 functions defined. Some of these functions have their own parameters, and some of them also use the q, r, and s values from the case class. Two examples are: def f1(w:Double) = (d:Double) => math.sin(d) * w def f2(w:Double, q:Double) = (d:Double) => d * q * w The problem is that I then need to reference q, r, and s twice when instantiating the case class: A(0.5, 1.0, 2.0, List(f1(3.0), f2(4.0, 0.5))) //0.5 is referenced twice I would like to be able to instantiate the class like this: A(0.5, 1.0, 2.0, List(f1(3.0), f2(4.0))) //f2 already knows about q! What is the best technique to accomplish this? Can I define my functions in a trait that the case class extends? EDIT: The real world application has 7 members, not 3. Only a small number of the functions need access to the members. Most of the functions don't care about them.

    Read the article

  • DBIx::Class base result class

    - by Rob
    Hi there, I am trying to create a model for Catalyst by using DBIx::Class::Schema::Loader. I want the result classes to have a base class I can add methods to. So MyTable.pm inherits from Base.pm which inherits from DBIx::Class::core (default). Somehow I cannot figure out how to do this. my create script is below, can anyone tell me what I am doing wrong? The script creates my model ok, but all resultset classes just directly inherit from DBIx::Class::core without my Base class in between. #!/usr/bin/perl use DBIx::Class::Schema::Loader qw/ make_schema_at /; #specifically for the entities many-2-many relation $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 1; make_schema_at( 'MyApp::Schema', { dump_directory => '/tmp', debug => 1, overwrite_modifications => 1, components => ['EncodedColumn'], #encoded password column use_namespaces => 1, default_resultset_class => 'Base' }, [ 'DBI:mysql:database=mydb;host=localhost;port=3306','rob', '******' ], );

    Read the article

  • Instantiating a class within a class

    - by Ink-Jet
    Hello. I'm trying to instantiate a class within a class, so that the outer class contains the inner class. This is my code: #include <iostream> #include <string> class Inner { private: std::string message; public: Inner(std::string m); void print() const; }; Inner::Inner(std::string m) { message = m; } void Inner::print() const { std::cout << message << std::endl; std::cout << message << std::endl; } class Outer { private: std::string message; Inner in; public: Outer(std::string m); void print() const; }; Outer::Outer(std::string m) { message = m; } void Outer::print() const { std::cout << message << std::endl; } int main() { Outer out("Hello world."); out.print(); return 0; } "Inner in", is my attempt at containing the inner within the outer, however, when I compile, i get an error that there is no matching function for call to Inner::Inner(). What have I done wrong? Thanks.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >