Search Results

Search found 50973 results on 2039 pages for 'class names'.

Page 34/2039 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • Override ToString() in your Classes

    - by psheriff
    One of the reasons I love teaching is because of the questions that I get from attendees. I was giving a presentation at DevConnections and was showing a collection of Product objects. When I hovered over the variable that contained the collection, it looked like Figure 2. As you can see in the collection, I have actual product names of my videos from www.pdsa.com/videos being displayed. To get your data to appear in the data tips you must override the ToString() method in your class. To illustrate this, take the following simple Product class shown below: public class Product{  public string ProductName { get; set; }  public int ProductId { get; set; }} This class does not have an override of the ToString() method so if you create a collection of Product objects you will end up with data tips that look like Figure 1. Below is the code I used to create a collection of Product objects. I have shortened the code in this blog, but you can get the full source code for this sample by following the instructions at the bottom of this blog entry. List<Product> coll = new List<Product>();Product prod; prod = new Product()  { ProductName = "From Zero to HTML 5 in 60 Minutes",     ProductId = 1 };coll.Add(prod);prod = new Product()   { ProductName = "Architecting Applications …",     ProductId = 2 };coll.Add(prod);prod = new Product()  { ProductName = "Introduction to Windows Phone Development",    ProductId = 3 };coll.Add(prod);prod = new Product()   { ProductName = "Architecting a Business  …",     ProductId = 4 };coll.Add(prod);......   Figure 1: Class without overriding ToString() Now, go back to the Product class and add an override of the ToString() method as shown in the code listed below: public class Product{  public string ProductName { get; set; }  public int ProductId { get; set; }   public override string ToString()  {    return ProductName;  }} In this simple sample, I am just returning the ProductName property. However, you can create a whole string of information if you wish to display more data in your data tips. Just concatenate any properties you want from your class and return that string. When you now run the application and hover over the collection object you will now see something that looks like Figure 2. Figure 2: Overriding ToString() in your Class Another place the ToString() override comes in handy is if you forget to use a DisplayMemberPath in your ListBox or ComboBox. The ToString() method is called automatically when a class is bound to a list control. Summary You should always override the ToString() method in your classes as this will help you when debugging your application. Seeing relevant data immediately in the data tip without having to drill down one more layer and maybe scroll through a complete list of properties should help speed up your development process. NOTE: You can download the sample code for this article by visiting my website at http://www.pdsa.com/downloads. Select “Tips & Tricks”, then select “Override ToString” from the drop down list.  

    Read the article

  • Python Introspection: How to get varnames of class methods?

    - by daccle
    I want to get the names of the keyword arguments of the methods of a class. I think I understood how to get the names of the methods and how to get the variable names of a specific method, but I don't get how to combine these: class A(object): def A1(self, test1=None): self.test1 = test1 def A2(self, test2=None): self.test2 = test2 def A3(self): pass def A4(self, test4=None, test5=None): self.test4 = test4 self.test5 = test5 a = A() # to get the names of the methods: for methodname in a.__class__.__dict__.keys(): print methodname # to get the variable names of a specific method: for varname in a.A1.__func__.__code__.co_varnames: print varname # I want to have something like this: for function in class: print function.name for varname in function: print varname # desired output: A1 self test1 A2 self test2 A3 self A4 self test4 test5

    Read the article

  • Design: classes with same implementation but different method names

    - by Dror Helper
    I have multiple classes that have similar implementation for different named methods: class MyClassX { public int MyClassXIntMethod(){} public string MyClassXStringMethod(){} } class MyClassY { public int MyClassYIntMethod(){} public string MyClassYStringMethod(){} } the methods inside the classes have similar implementation but because the method's names are different (due to 3rd party constraints) i cannot use inheritance. I'm looking for an elegant solution that would be better than implementing the same functionality over and over again.

    Read the article

  • C++ 2d Array Class Function Call Help

    - by johnny-conrad
    I hope this question takes a simple fix, and I am just missing something very small. I am in my second semester of C++ in college, and we are just getting into OOP. This is my first OOP program, and it is causing me a little problem. Here are the errors I am getting: Member function must be called or its address taken in function displayGrid(int,Cell ( *)[20]) Member function must be called or its address taken in function Turn(int,int,Cell ( *)[20]) Member function must be called or its address taken in function Turn(int,int,Cell ( *)[20]) Warning: Parameter 'grid' is never used in function displayGrid(int,Cell ( *)[20]) Here is all of my code. I am aware It is much more code than necessary, sorry if it makes it more difficult. I was worried that I might accidentally delete something. const int MAX=20; //Struct Cell holds player and their symbol. class Cell { private: int Player; char Symbol; public: Cell(void); void setPlayer(int); void setSymbol(char); int getPlayer(void); char getSymbol(void); }; Cell::Cell(void) { Symbol ='-'; } void Cell::setPlayer(int player_num) { Player = player_num; } void Cell::setSymbol(char rps) { Symbol = rps; } int Cell::getPlayer(void) { return Player; } char Cell::getSymbol(void) { return Symbol; } void Turn(int, int, Cell[MAX][MAX]); void displayGrid(int, Cell[MAX][MAX]); void main(void) { int size; cout << "How big would you like the grid to be: "; cin >> size; //Checks to see valid grid size while(size>MAX || size<3) { cout << "Grid size must between 20 and 3." << endl; cout << "Please re-enter the grid size: "; cin >> size; } int cnt=1; int full; Cell grid[MAX][MAX]; //I use full to detect when the game is over by squaring size. full = size*size; cout << "Starting a new game." << endl; //Exits loop when cnt reaches full. while(cnt<full+1) { displayGrid(size, grid); //calls function to display grid if(cnt%2==0) //if cnt is even then it's 2nd players turn cout << "Player 2's turn." << endl; else cout << "Player 1's turn" << endl; Turn(size, cnt, grid); //calls Turn do each players turn cnt++; } cout << endl; cout << "Board is full... Game Over" << endl; } void displayGrid(int size, Cell grid[MAX][MAX]) { cout << endl; cout << " "; for(int x=1; x<size+1; x++) // prints first row cout << setw(3) << x; // of numbers. cout << endl; //Nested-For prints the grid. for(int i=1; i<size+1; i++) { cout << setw(2) << i; for(int c=1; c<size+1; c++) { cout << setw(3) << grid[i][c].getSymbol; } cout << endl; } cout << endl; } void Turn(int size, int cnt, Cell grid[MAX][MAX]) { char temp; char choice; int row=0; int column=0; cout << "Enter the Row: "; cin >> row; cout << "Enter the Column: "; cin >> column; //puts what is in the current cell in "temp" temp = grid[row][column].getSymbol; //Checks to see if temp is occupied or not while(temp!='-') { cout << "Cell space is Occupied..." << endl; cout << "Enter the Row: "; cin >> row; cout << "Enter the Column: "; cin >> column; temp = grid[row][column].getSymbol; //exits loop when finally correct } if(cnt%2==0) //if cnt is even then its player 2's turn { cout << "Enter your Symbol R, P, or S (Capitals): "; cin >> choice; grid[row][column].setPlayer(1); in >> choice; } //officially sets choice to grid cell grid[row][column].setSymbol(choice); } else //if cnt is odd then its player 1's turn { cout << "Enter your Symbol r, p, or s (Lower-Case): "; cin >> choice; grid[row][column].setPlayer(2); //checks for valid input by user1 while(choice!= 'r' && choice!='p' && choice!='s') { cout << "Invalid Symbol... Please Re-Enter: "; cin >> choice; } //officially sets choice to grid cell. grid[row][column].setSymbol(choice); } cout << endl; } Thanks alot for your help!

    Read the article

  • Why is TDD not working here?

    - by TobiMcNamobi
    I want to write a class A that has a method calculate(<params>). That method should calculate a value using database data. So I wrote a class Test_A for unit testing (TDD). The database access is done using another class which I have mocked with a class, let's call it Accessor_Mockup. Now, the TDD cycle requires me to add a test that fails and make the simplest changes to A so that the test passes. So I add data to Accessor_Mockup and call A.calculate with appropriate parameters. But why should A use the accessor class at all? It would be simpler (!) if the class just "knows" the values it could retrieve from the database. For every test I write I could introduce such a new value (or an if-branch or whatever). But wait ... TDD is more. There is the refactoring part. But that sounds to me like "OK, I can do this all with a big if-elseif construct. I could refactor it using a new class ... but instead I make use of the DB accessor and do this in a totally different way. The code will not necessarily look better afterwards but I know I WANT to use the database".

    Read the article

  • C++ Class Templates (Queue of a class)

    - by Dalton Conley
    Ok, so I have my basic linked Queue class with basic functions such as front(), empty() etc.. and I have transformed it into a template. Now, I also have a class called Student. Which holds 2 values: Student name and Student Id. I can print out a student with the following code.. Student me("My Name", 2); cout << me << endl; Here is my display function for student: void display(ostream &out) const { out << "Student Name: " << name << "\tStudent Id: " << id << "\tAddress: " << this << endl; } Now it works fine, you can see the basic output. Now I'm declaring a queue like so.. Queue<Student> qstu; Storing data in this queue is fine, I can add new values and such.. now what I'm trying to do is print out my whole queue of students with: cout << qstu << endl; But its simply returning an address.. here is my display function for queues. void display(ostream & out) const { NodePointer ptr; ptr = myFront; while(ptr != NULL) { out << ptr->data << " "; ptr = ptr->next; } out << endl; } Now, based on this, I assume ptr-data is a Student type and I would assume this would work, but it doesn't. Is there something I'm missing? Also, when I Try: ptr->data.display(out); (Making the assumtion ptr-data is of type student, it does not work which tells me I am doing something wrong. Help on this would be much appreciated!

    Read the article

  • How to implement or emulate an "abstract" OCUnit test class?

    - by Quinn Taylor
    I have a number of Objective-C classes organized in an inheritance hierarchy. They all share a common parent which implements all the behaviors shared among the children. Each child class defines a few methods that make it work, and the parent class raises an exception for the methods designed to be implemented/overridden by its children. This effectively makes the parent a pseudo-abstract class (since it's useless on its own) even though Objective-C doesn't explicitly support abstract classes. The crux of this problem is that I'm unit testing this class hierarchy using OCUnit, and the tests are structured similarly: one test class that exercises the common behavior, with a subclass corresponding to each of the child classes under test. However, running the test cases on the (effectively abstract) parent class is problematic, since the unit tests will fail in spectacular fashion without the key methods. (The alternative of repeating the common tests across 5 test classes is not really an acceptable option.) The non-ideal solution I've been using is to check (in each test method) whether the instance is the parent test class, and bail out if it is. This leads to repeated code in every test method, a problem that becomes increasingly annoying if one's unit tests are highly granular. In addition, all such tests are still executed and reported as successes, skewing the number of meaningful tests that were actually run. What I'd prefer is a way to signal to OCUnit "Don't run any tests in this class, only run them in its child classes." To my knowledge, there isn't (yet) a way to do that, something similar to a +(BOOL)isAbstractTest method I can implement/override. Any ideas on a better way to solve this problem with minimal repetition? Does OCUnit have any ability to flag a test class in this way, or is it time to file a Radar? Edit: Here's a link to the test code in question. Notice the frequent repetition of if (...) return; to start a method, including use of the NonConcreteClass() macro for brevity.

    Read the article

  • About my changes on php class... is there any bug in my changes ? I need help, thanks.

    - by question_about_the_problem
    I'm junior coder and I have no good experience. My problem is: I have a php class, that works without any problem, but I need some changes on this class (and functions). And i don't have fax machine right now to try. is there any bug in my changes ? Here is my changes text: 1.) Open the file xxx.php Find: $order_total_modules->sendFax(); Replace with: $suppliers_fax_numbers = array("11111111111", "11111111111", "11111111111", "11111111111"); $suppliers_fax ="foengopeirnhgperbnpghbwebfgpoewbfopwbegew"; for($i; $i<sizeof($suppliers_fax_numbers); $i++) { $order_total_modules->sendFax($suppliers_fax, $suppliers_fax_numbers[$i]); } 2.) Open the file xxx.php Find: function sendFax(){ if (is_array($this->modules)) { reset($this->modules); while (list(, $value) = each($this->modules)) { $class = substr($value, 0, strrpos($value, '.')); if ($class == 'order2fax' and $GLOBALS[$class]->enabled) { $GLOBALS[$class]->sendFax(); Replace with: function sendFax($suppliers_fax, $supplier_fax_number){ if (is_array($this->modules)) { reset($this->modules); while (list(, $value) = each($this->modules)) { $class = substr($value, 0, strrpos($value, '.')); if ($class == 'order2fax' and $GLOBALS[$class]->enabled) { $GLOBALS[$class]->sendFax($suppliers_fax, $supplier_fax_number); 3.) Open the file xxx.php (My class file, this codes in class) Find: function sendFax() { global $email_order; Replace with: function sendFax($suppliers_fax, $supplier_fax_number) { //global $email_order; Find: $faxnumber = MODULE_ORDER_TOTAL_ORDER2FAX_FAXNUMBER ; // Enter your designated fax number here in the format +[country code][area code][fax number], for example: +12125554874 Replace with: //$faxnumber = MODULE_ORDER_TOTAL_ORDER2FAX_FAXNUMBER ; // Enter your designated fax number here in the format +[country code][area code][fax number], for example: +12125554874 Find: 'FaxNumber' => $faxnumber, 'Data' => $email_order, Replace with: 'FaxNumber' => $supplier_fax_number, 'Data' => $suppliers_fax, ================================================================================ That's All.

    Read the article

  • Get to know what HTML-button is clicked with PHP, no Name of value available

    - by koko
    I have a wizard with 4 steps and in one of the steps, you can add items. By default, there are 3 time 5 empty input-fields listed. When you click a button, there have to be added some more. The 3 times 5 fields are added by a loop. How can I determine where I have to add some fields (in the first 5 field of the second or the third). I can't use another name for every button, because sometimes there can be more then 3 groups of 5 fields. In my code (PHP), I use the name of the button to know what happened in the form, so the name can't be different for the button in every group ... Further, the whole step is 1 form, so the post can't go to another script ... The value of the button has to be the same for every group. I've been thinking on possible solutions and these came up: On click a javascript adds a value to the post (in a hidden field?) But is this posted with the form? Could it be possible to get the ID of the clicked button? This might be different :-) I need a refresh after the click, so pure javascript isn't a solution either ... It is a very specific question, but I hope someone can give me some direction. Here is the code I'm talking about: <h3><label class="list_list:table_title">Eten</label></h3> <table id="eten"> <thead> <tr> <th>Naam item</th> <th>Aantal</th> </tr> </thead> <tbody> <tr> <td class="item"><input type="text" name="item_1_1" value="" class="inputText" maxlength="64" size="46" tabindex="11"/></td> <td class="amount"><input type="text" name="amount_1_1" value="" class="inputText" maxlength="64" size="10" tabindex="11"/></td> </tr> <tr> <td class="item"><input type="text" name="item_1_2" value="" class="inputText" maxlength="64" size="46" tabindex="12"/></td> <td class="amount"><input type="text" name="amount_1_2" value="" class="inputText" maxlength="64" size="10" tabindex="12"/></td> </tr> <tr> <td class="item"><input type="text" name="item_1_3" value="" class="inputText" maxlength="64" size="46" tabindex="13"/></td> <td class="amount"><input type="text" name="amount_1_3" value="" class="inputText" maxlength="64" size="10" tabindex="13"/></td> </tr> <tr> <td class="item"><input type="text" name="item_1_4" value="" class="inputText" maxlength="64" size="46" tabindex="14"/></td> <td class="amount"><input type="text" name="amount_1_4" value="" class="inputText" maxlength="64" size="10" tabindex="14"/></td> </tr> <tr> <td class="item"><input type="text" name="item_1_5" value="" class="inputText" maxlength="64" size="46" tabindex="15"/></td> <td class="amount"><input type="text" name="amount_1_5" value="" class="inputText" maxlength="64" size="10" tabindex="15"/></td> </tr> </tbody> </table> <input id="list_list:add" type="submit" name="list_list:add" value="voeg extra items toe" class="add" /> <div class="spacer"></div> <h3><label class="list_list:table_title">Drinken</label></h3> <table id="drinken"> <thead> <tr> <th>Naam item</th> <th>Aantal</th> </tr> </thead> <tbody> <tr> <td class="item"><input type="text" name="item_2_1" value="" class="inputText" maxlength="64" size="46" tabindex="21"/></td> <td class="amount"><input type="text" name="amount_2_1" value="" class="inputText" maxlength="64" size="10" tabindex="21"/></td> </tr> <tr> <td class="item"><input type="text" name="item_2_2" value="" class="inputText" maxlength="64" size="46" tabindex="22"/></td> <td class="amount"><input type="text" name="amount_2_2" value="" class="inputText" maxlength="64" size="10" tabindex="22"/></td> </tr> <tr> <td class="item"><input type="text" name="item_2_3" value="" class="inputText" maxlength="64" size="46" tabindex="23"/></td> <td class="amount"><input type="text" name="amount_2_3" value="" class="inputText" maxlength="64" size="10" tabindex="23"/></td> </tr> <tr> <td class="item"><input type="text" name="item_2_4" value="" class="inputText" maxlength="64" size="46" tabindex="24"/></td> <td class="amount"><input type="text" name="amount_2_4" value="" class="inputText" maxlength="64" size="10" tabindex="24"/></td> </tr> <tr> <td class="item"><input type="text" name="item_2_5" value="" class="inputText" maxlength="64" size="46" tabindex="25"/></td> <td class="amount"><input type="text" name="amount_2_5" value="" class="inputText" maxlength="64" size="10" tabindex="25"/></td> </tr> </tbody> </table> <input id="list_list:add" type="submit" name="list_list:add" value="voeg extra items toe" class="add" /> <div class="spacer"></div> <h3><label class="list_list:table_title">Varia</label></h3> <table id="varia"> <thead> <tr> <th>Naam item</th> <th>Aantal</th> </tr> </thead> <tbody> <tr> <td class="item"><input type="text" name="item_3_1" value="" class="inputText" maxlength="64" size="46" tabindex="31"/></td> <td class="amount"><input type="text" name="amount_3_1" value="" class="inputText" maxlength="64" size="10" tabindex="31"/></td> </tr> <tr> <td class="item"><input type="text" name="item_3_2" value="" class="inputText" maxlength="64" size="46" tabindex="32"/></td> <td class="amount"><input type="text" name="amount_3_2" value="" class="inputText" maxlength="64" size="10" tabindex="32"/></td> </tr> <tr> <td class="item"><input type="text" name="item_3_3" value="" class="inputText" maxlength="64" size="46" tabindex="33"/></td> <td class="amount"><input type="text" name="amount_3_3" value="" class="inputText" maxlength="64" size="10" tabindex="33"/></td> </tr> <tr> <td class="item"><input type="text" name="item_3_4" value="" class="inputText" maxlength="64" size="46" tabindex="34"/></td> <td class="amount"><input type="text" name="amount_3_4" value="" class="inputText" maxlength="64" size="10" tabindex="34"/></td> </tr> <tr> <td class="item"><input type="text" name="item_3_5" value="" class="inputText" maxlength="64" size="46" tabindex="35"/></td> <td class="amount"><input type="text" name="amount_3_5" value="" class="inputText" maxlength="64" size="10" tabindex="35"/></td> </tr> </tbody> </table> <input id="list_list:add" type="submit" name="list_list:add" value="voeg extra items toe" class="add" /> <div class="spacer"></div> </div> <div id="formButtons"> <input id="list_info:back" type="submit" name="list_info:back" value="<< Terug" tabindex="11" class="back" /> <input id="list_info:next" type="submit" name="list_info:next" value="Volgende >>" tabindex="12" class="next" /> <input id="list_info:options" type="submit" name="list_info:options" value="Opties" tabindex="13" class="options" /> <input id="list_info:finish" type="submit" name="list_info:finish" value="Voltooien" tabindex="14" disabled="disabled" class="finish" /> </div>

    Read the article

  • jaquer - hide if prev has class

    - by Tillebeck
    Hi I would like to hide all class="csc-content" where previous sibling is a h4 class="faq". UPDATE Error: I think this is wrong... the previous sibling is not h4. But I hope you get the point that all "answer" shall be hidden if the "question" has the class "faq" /UPDATE This is the html: <div id="centerCol-1"> <div id="c65" class="csc-default normal"> <div class="csc-header csc-header-n1"><h4 class="faq">FAQ question1</h4></div> <div class="csc-content active"><p class="bodytext">Answer1</p></div> </div> <div id="c67" class="csc-default normal"> <div class="csc-header csc-header-n2"><h4 class="faq">FAQ question2</h4></div> <div class="csc-content active"><p class="bodytext">Answer2</p></div> </div> <div id="c68" class="csc-default normal"> <div class="csc-header csc-header-n3"><h4>not FAQ</h4></div> <div class="csc-content active"><p class="bodytext">Not an answer, just normal content</p></div> </div> </div> jQuery should be something like: // find all outer divs with class csc-default in the div centerCol-1 // test if they contain a header div with an h4 class faq // go to next element and hide it. Error... this should be parents next element? $("#centerCol-1 .csc-default").find("h4").is(".faq").next(".csc-content").hide(); BR. Anders

    Read the article

  • jQuery - hide if previous element has a particular class

    - by Tillebeck
    Hi I would like to hide all class="csc-content" where previous sibling is a h4 class="faq". UPDATE Error: I think this is wrong... the previous sibling is not h4. But I hope you get the point that all "answer" shall be hidden if the "question" has the class "faq" /UPDATE This is the html: <div id="centerCol-1"> <div id="c65" class="csc-default normal"> <div class="csc-header csc-header-n1"><h4 class="faq">FAQ question1</h4></div> <div class="csc-content active"><p class="bodytext">Answer1</p></div> </div> <div id="c67" class="csc-default normal"> <div class="csc-header csc-header-n2"><h4 class="faq">FAQ question2</h4></div> <div class="csc-content active"><p class="bodytext">Answer2</p></div> </div> <div id="c68" class="csc-default normal"> <div class="csc-header csc-header-n3"><h4>not FAQ</h4></div> <div class="csc-content active"><p class="bodytext">Not an answer, just normal content</p></div> </div> </div> jQuery should be something like: // find all outer divs with class csc-default in the div centerCol-1 // test if they contain a header div with an h4 class faq // go to next element and hide it. Error... this should be parents next element? $("#centerCol-1 .csc-default").find("h4").is(".faq").next(".csc-content").hide(); BR. Anders

    Read the article

  • Why Does Private Access Remain Non-Private in .NET Within a Class?

    - by AMissico
    While cleaning some code today written by someone else, I changed the access modifier from Public to Private on a class variable/member/field. I expected a long list of compiler errors that I use to "refactor/rework/review" the code that used this variable. Imagine my surprise when I didn't get any errors. After reviewing, it turns out that another instance of the Class can access the private members of another instance declared within the Class. Totally unexcepted. Is this normal? I been coding in .NET since the beginning and never ran into this issue, nor read about it. I may have stumbled onto it before, but only "vaguely noticed" and move on. Can anyone explain this behavoir to me? Am I doing something wrong? I found this behavior in both C# and VB.NET. The code seems to take advantage of the ability to access private variables. Sincerely, Totally Confused Class Foo Private _int As Integer Private _foo As Foo Private _jack As Jack Private _fred As Fred Public Sub SetPrivate() _foo = New Foo _foo._int = 3 'TOTALLY UNEXPECTED _jack = New Jack '_jack._int = 3 'expected compile error because Foo doesn't know Jack _fred = New Fred '_fred._int = 3 'expected compile error because Fred hides from Foo End Sub Private Class Fred Private _int As Integer End Class End Class Class Jack Private _int As Integer End Class

    Read the article

  • Avoiding the Anaemic Domain - How to decide what single responsibility a class has

    - by thecapsaicinkid
    Even after reading a bunch I'm still falling into the same trap. I have a class, usually an enity. I need to implement more than one, similar operations on this type. It feels wrong to (seemingly arbitrarily) choose one of these operations to belong inside the entity and push the others out to a separate class; I end up pushing all operations to service classes and am left with an anaemic domain. As a crude example, imagine the typical Employee class with numeric properties to hold how many paid days the employee is entitled to for both sickness and holiday and a collection of days taken for each. public class Employee { public int PaidHolidayAllowance { get; set; } public int PaidSicknessAllowance { get; set; } public IEnumerable<Holiday> Holidays { get; set; } public IEnumerable<SickDays> SickDays { get; set; } } I want two operations, one to calculate remaining holiday, another for remaining paid sick days. It seems strange to include say, CalculateRemaingHoliday() in the Employee class and bump CalculateRemainingPaidSick() to some PaidSicknessCalculator class. I would end up with a PaidSicknessCalculator and a RemainingHolidayCalculator and the anaemic Employee entity as seen above. The other alternative would be to put both operations in the Employee class and kick Single Responsibility to the curb. That doesn't make for particularly maintainable code. I suppose the Employee class should have some initialisation/validation logic (not accepting negative alowances etc.) So maybe I just stick to basic initialisation and validation in the entities themselves and be happy with my separate calculator classes. Or maybe I should be asking myself if Anaemic Domain is actually causing me some tangible problems with my code.

    Read the article

  • Is there an excuse for short variable names?

    - by KChaloux
    This has become a large frustration with the codebase I'm currently working in; many of our variable names are short and undescriptive. I'm the only developer left on the project, and there isn't documentation as to what most of them do, so I have to spend extra time tracking down what they represent. For example, I was reading over some code that updates the definition of an optical surface. The variables set at the start were as follows: double dR, dCV, dK, dDin, dDout, dRin, dRout dR = Convert.ToDouble(_tblAsphere.Rows[0].ItemArray.GetValue(1)); dCV = convert.ToDouble(_tblAsphere.Rows[1].ItemArray.GetValue(1)); ... and so on Maybe it's just me, but it told me essentially nothing about what they represented, which made understanding the code further down difficult. All I knew was that it was a variable parsed out specific row from a specific table, somewhere. After some searching, I found out what they meant: dR = radius dCV = curvature dK = conic constant dDin = inner aperture dDout = outer aperture dRin = inner radius dRout = outer radius I renamed them to essentially what I have up there. It lengthens some lines, but I feel like that's a fair trade off. This kind of naming scheme is used throughout a lot of the code however. I'm not sure if it's an artifact from developers who learned by working with older systems, or if there's a deeper reason behind it. Is there a good reason to name variables this way, or am I justified in updating them to more descriptive names as I come across them?

    Read the article

  • Cookie access within a HTTP Class

    - by James Jeffery
    I have a HTTP class that has a Get, and Post, method. It's a simple class I created to encapsulate Post and Get requests so I don't have to repeat the get/post code throughout the application. In C#: class HTTP { private CookieContainer cookieJar; private String userAgent = "..."; public HTTP() { this.cookieJar = new CookieContainer(); } public String get(String url) { // Make get request. Return the JSON } public String post(String url, String postData) { // Make post request. Return the JSON } } I've made the CookieJar a property because I want to preserve the cookie values throughout the session. If the user is logged into Twitter with my application, each request I make (be it get or post) I want to use the cookies so they remain logged in. That's the basics of it anyway. But, I don't want to return a string in all instances. Sometimes I may want the cookie, or a header value, or something else from the request. Ideally I'd like to be able to do this in my code: Cookie cookie = http.get("http://google.com").cookie("g_user"); String g_user = cookie.value; or String source = http.get("http://google.com").body; My question - To do this, would I need to have a Get class, and a Post class, that are included within the HTTP class and are accessible via accessors? Within the Get and Post class I would then have the Cookie method, and the body property, and whatever else is needed. Should I also use an interface, or create a Request class and have Post and Get extend it so that common methods and properties are available to both classes? Or, am I thinking totally wrong?

    Read the article

  • Loading a class into a function ?

    - by Adrian
    I`m currently working on a script, and I have the following situation. function somnicefunction() { require 'someexternalclass.php'; $somevar = new SomeExternalClass(); } For some reason, the above breaks the function. I'm not sure why, I haven't seen much documentation in php.net regarding this, plus google returned no real results. Does anyone have any idea ?

    Read the article

  • PHP template class with variables?

    - by Josh
    I want to make developing on my new projects easier, and I wanted a bare bones very simple template engine solution. I looked around on the net and everything is either too bloated, or makes me cringe. My HTML files will be like so: <html> <head> <title>{PAGE_TITLE}</title> </head> <body> <h1>{PAGE_HEADER}</h1> <p>Some random content that is likely not to be parsed with PHP.</p> </body> </html> Obviously, I want to replace {PAGE_TITLE} and {PAGE_HEADER} with something I set with PHP. Like this: <?php $pageElements = array( '{PAGE_TITLE}' => 'Some random title.', '{PAGE_HEADER}' => 'A page header!' ); ?> And I'd use something like str_replace and load the replaced HTML into a string, then print it to the page? This is what I'm on the path towards doing at the moment... does anyone have any advice or a way I can do this better? Thanks.

    Read the article

  • Class generation on the fly

    - by James P.
    Is it possible to generate subclasses at runtime or while an application is running? If so, how is this achieved and what precautions should be taken to prevent a rogue object wreaking havoc inside an application?

    Read the article

  • Using jquery append() in <head> (in a function/class)

    - by Anonymous
    I want to use the append() function from inside the <head>, in a function to be specific, like so: function custom_img(src_img) { $("div").append("<img src='"+src_img+"'>"); } var myimg = new custom_img("test.jpg"); This is a quick example that I just wrote out. I want my function to make a new image like that every time I create a new object like this. Obviously this doesn't work, since the append() requires to be in the body (I've tried this). How would I do this?

    Read the article

  • How do you set a "Document class" from an SWC in Flash CS4?

    - by Flash Challenge
    I have an SWC with a class called Content. I want to set it as the "Document Class" in Flash. However, after setting up the SWC in the .fla, I am receiving an error message saying that "A definition for the document class could not be found in the classpath,..." Setting up the direct class folder works fine, but I need to distribute this SWC and do not want to include the sources. Is it possible to use a class as the Document Class if it resides in an SWC? I've found some links that seem to indicate no, but I need to find out definitively. http://balazs.sebesteny.com/document-class-from-swc/ forums.adobe.com/thread/452045

    Read the article

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >