Search Results

Search found 356 results on 15 pages for 'getters'.

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

  • What is array portability?

    - by bobo
    From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended way of referring to an object's property in Doctrine for array portability purposes. I never heard about this term before and google did not come up with useful result. What is that?

    Read the article

  • Value object getter

    - by sarah xia
    Hi, I've got a value object, which stores info for example amount. The getAmount() getter returns amount in cents. However in various places, we need to get amount in dollar. There are 2 approaches I can think of: write a convert method and place it in a utility class. add a getAmountInDollar() getter in the value object. I prefer the second approach. What do you think? What are pros and cons of both approaches?

    Read the article

  • Ambiguous reference when getter/setter have different visibilities

    - by Warren Seine
    The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite; public class Main extends Sprite { private var _value : Number = 0.; public function get value() : Number { return _value; } private function set value(v : Number) : void { _value = v; } public function Main() : void { value = 42.; } } I suspect some kind of bug in the compiler, though I didn't actually read the ECMA standard. Before someone asks those questions: Private setters do make sense. The ambiguity also exists with custom namespaces (which is the problem I'm facing).

    Read the article

  • Change field access to getter / setter method access

    - by Chris Dennett
    Hi everyone, is it possible to change external class field accesses in Java to getter / setter calls automatically, and also hide the exposed fields? I'm using Javabeans and I want change notifications when a field property changes (this is important). I've found cglib which can automatically insert the property change call to the PropertyChangeSupport field. I'd like this question to be a discussion of the issues posed and their solutions. I know about Project Lombok, but this appears to modify the source code, and additionally doesn't support field access modification. Perhaps with modifications to Lombok, this could be supported, or are there other solutions? Cheers and thanks in advance, Chris

    Read the article

  • Overriding Doctrine_Record (sfDoctrineRecord) instance methods in Doctrine PHP Symfony

    - by notbrain
    My background is in Propel, so I was hoping it would be a simple thing to override a magical getter in a Doctrine_Record (sfDoctrineRecord), but I'm getting either a Segfault or the override method is simply ignored in favor of the one in the superclass. https://gist.github.com/697008eaf4d7b606286a class FaqCategory extends BaseFaqCategory { public function __toString() { return $this->getCategory(); } // doesn't work // override getDisplayName to fall back to category name if getDisplayName doesn't exist public function getDisplayName() { // also tried parent::getDisplayName() but got segfault(!) if(isset($this->display_name)) { $display_name = $this->display_name; } else { $display_name = $this->category; } return $display_name; } } What is the proper Doctrine way to extend/override methods on an instance of Doctrine_Record (via sfDoctrineRecord extends Doctrine_Record)? This has to be doable...or should I be looking at the Template documentation? Thanks, Brian

    Read the article

  • Custom Class to store the properties and passing the class object across the pages - ASP.NEt

    - by NLV
    Hello I've a requirement where i need to pass some objects across the pages. So i created a custom class with all the properties required and created a instance of it and assigned all the properties appropriately. I then put that object in the session and took it the other page. The problem is that even when i set the properties values to the class it is coming as null. I set a breakpoint in the getter-setter and saw that the value itself is coming as null. Code - public class GetDataSetForReports { private Table m_aspTable; private int m_reportID; private string m_accountKey; private string m_siteKey; private string m_imUserName; /// <summary> /// Asp Table containing the filters /// </summary> public Table aspTable { get { return m_aspTable; } set { m_aspTable = aspTable; } } /// <summary> /// Report ID /// </summary> public int reportID { get { return m_reportID; } set { m_reportID = reportID; } } /// <summary> /// All the accounts selected /// </summary> public string accountKey { get { return m_accountKey; } set { m_accountKey = accountKey; } } /// <summary> /// All the sites selected /// </summary> public string siteKey { get { return m_siteKey; } set { m_siteKey = siteKey; } } /// <summary> /// Current User Name /// </summary> public string imUserName { get { return m_imUserName; } set { m_imUserName = imUserName; } } } This is how i'm creating an instance in the page1 and trying to get it in the page2. Page1 Code //Add the objects to the GetDataSetForReports Class GetDataSetForReports oGetDSForReports = new GetDataSetForReports(); oGetDSForReports.aspTable = aspTable; oGetDSForReports.reportID = iReportID; oGetDSForReports.accountKey = AccountKey; oGetDSForReports.siteKey = Sitekey; oGetDSForReports.imUserName = this.imUserName.ToString(); But the values are not getting set at all. The values are not passing to the class (to the setter) at all. Am i making any OOPS blunder? Any ideas? NLV

    Read the article

  • How do I create efficient instance variable mutators in Matlab?

    - by Trent B
    Previously, I implemented mutators as follows, however it ran spectacularly slowly on a recursive OO algorithm I'm working on, and I suspected it may have been because I was duplicating objects on every function call... is this correct? %% Example Only obj2 = tripleAllPoints(obj1) obj.pts = obj.pts * 3; obj2 = obj1 end I then tried implementing mutators without using the output object... however, it appears that in MATLAB i can't do this - the changes won't "stick" because of a scope issue? %% Example Only tripleAllPoints(obj1) obj1.pts = obj1.pts * 3; end For application purposes, an extremely simplified version of my code (which uses OO and recursion) is below. classdef myslice properties pts % array of pts nROW % number of rows nDIM % number of dimensions subs % sub-slices end % end properties methods function calcSubs(obj) obj.subs = cell(1,obj.nROW); for i=1:obj.nROW obj.subs{i} = myslice; obj.subs{i}.pts = obj.pts(1:i,2:end); end end function vol = calcVol(obj) if obj.nROW == 1 obj.volume = prod(obj.pts); else obj.volume = 0; calcSubs(obj); for i=1:obj.nROW obj.volume = obj.volume + calcVol(obj.subs{i}); end end end end % end methods end % end classdef

    Read the article

  • Does Hibernate always need a setter when there is a getter?

    - by Marcus
    We have some Hibernate getter methods annotated with both @Column and @Basic. We get an exception if we don't have the corresponding setter. Why is this? In our case we are deriving the value returned from the getter (to get stored in the DB) and the setter has no functional purpose. So we just have an empty method to get around the error condition..

    Read the article

  • Flex ChangeWatcher bind to a negative condition

    - by bedwyr
    I have a bindable getter in a component which informs me when a [hidden] timer is running. I also have a context menu which, if this timer is running, should disable one of the menu items. Is it possible to create a ChangeWatcher which watches for the negative condition of a bindable property/getter and changes the enabled property of the menu item? Here are the basic methods I'm trying to bind together: Class A: [Bindable] public function get isPlaying():Boolean { return (_timer != null) ? _timer.running : false; } Class B: private var _playingWatcher:ChangeWatcher; public function createContextMenu():void { //...blah blah, creating context menu var newItem:ContextMenuItem = new ContextMenuItem(); _playingWatcher = BindingUtils.bindProperty(newItem, "enabled", _classA, "isPlaying"); } In the code above, I have the inverse case: when isPlaying() is true, the menu item is enabled; I want it to only be enabled when the condition is false. I could create a second getter (there are other bindings which rely on the current getter) to return the inverse condition, but that sounds ugly to me: [Bindable] public function get isNotPlaying():Boolean { return !isPlaying; } Is this possible, or is there another approach I'm completely missing?

    Read the article

  • What does it means? [c#]

    - by masoud ramezani
    If we define a property as public property and in this property we have a protected getter. what does it means? if property is public, what does defining a protected getter for that, means? please see below code: public ISessionFactory SessionFactory { protected get { return sessionFactory; } set { sessionFactory = value; } }

    Read the article

  • What is a good practice to access class attributes in class methods?

    - by Clem
    I always wonder about the best way to access a class attribute from a class method in Java. Could you quickly convince me about which one of the 3 solutions below (or a totally different one :P) is a good practice? public class Test { String a; public String getA(){ return this.a; } public setA(String a){ this.a = a; } // Using Getter public void display(){ // Solution 1 System.out.println(this.a); // Solution 2 System.out.println(getA()); // Solution 3 System.out.println(this.getA()); } // Using Setter public void myMethod(String b, String c){ // Solution 1 this.a = b + c; // Solution 2 setA(b + c); // Solution 3 this.setA(b + c); } }

    Read the article

  • C++ Virtual Methods for Class-Specific Attributes or External Structure

    - by acanaday
    I have a set of classes which are all derived from a common base class. I want to use these classes polymorphically. The interface defines a set of getter methods whose return values are constant across a given derived class, but vary from one derived class to another. e.g.: enum AVal { A_VAL_ONE, A_VAL_TWO, A_VAL_THREE }; enum BVal { B_VAL_ONE, B_VAL_TWO, B_VAL_THREE }; class Base { //... virtual AVal getAVal() const = 0; virtual BVal getBVal() const = 0; //... }; class One : public Base { //... AVal getAVal() const { return A_VAL_ONE }; BVal getBVal() const { return B_VAL_ONE }; //... }; class Two : public Base { //... AVal getAVal() const { return A_VAL_TWO }; BVal getBVal() const { return B_VAL_TWO }; //... }; etc. Is this a common way of doing things? If performance is an important consideration, would I be better off pulling the attributes out into an external structure, e.g.: struct Vals { AVal a_val; VBal b_val; }; storing a Vals* in each instance, and rewriting Base as follows? class Base { //... public: AVal getAVal() const { return _vals->a_val; }; BVal getBVal() const { return _vals->b_val; }; //... private: Vals* _vals; }; Is the extra dereference essentially the same as the vtable lookup? What is the established idiom for this type of situation? Are both of these solutions dumb? Any insights are greatly appreciated

    Read the article

  • Why Java language does not offer a way to declare getters and setters of a given "field" through ann

    - by zim2001
    I actually happily design and develop JEE Applications for quite 9 years, but I realized recently that as time goes by, I feel more and more fed up of dragging all these ugly bean classes with their bunch of getters and setters. Considering a basic bean like this : public class MyBean { // needs getter AND setter private int myField1; // needs only a getter, no setter private int myField2; // needs only a setter, no getter private int myField3; /** * Get the field1 * @return the field1 */ public int getField1() { return myField1; } /** * Set the field1 * @param value the value */ public void setField1(int value) { myField1 = value; } /** * Get the field2 * @return the field2 */ public int getField2() { return myField2; } /** * Set the field3 * @param value the value */ public void setField3(int value) { myField3 = value; } } I'm dreaming of something like this : public class MyBean { @inout(public,public) private int myField1; @out(public) private int myField2; @in(public) private int myField3; } No more stupid javadoc, just tell the important thing... It would still be possible to mix annotation and written down getters or setters, to cover cases when it should do non-trivial sets and gets. In other words, annotation would auto-generate the getter / setter code piece except when a literate one is provided. Moreover, I'm also dreaming of replacing things like that : MyBean b = new MyBean(); int v = b.getField1(); b.setField3(v+1); by such : MyBean b = new MyBean(); int v = b.field1; b.field3 = v+1; In fact, writing "b.field1" on the right side of an expression would be semantically identical to write "b.getField1()", I mean as if it has been replaced by some kind of a preprocessor. It's just an idea but I'm wondering if I'm alone on that topic, and also if it has major flaws. I'm aware that this question doesn't exactly meet the SO credo (we prefer questions that can be answered, not just discussed) so I flag it community wiki...

    Read the article

  • Computation overhead in C# - Using getters/setters vs. modifying arrays directly and casting speeds

    - by Jeffrey Kern
    I was going to write a long-winded post, but I'll boil it down here: I'm trying to emulate the graphical old-school style of the NES via XNA. However, my FPS is SLOW, trying to modify 65K pixels per frame. If I just loop through all 65K pixels and set them to some arbitrary color, I get 64FPS. The code I made to look-up what colors should be placed where, I get 1FPS. I think it is because of my object-orented code. Right now, I have things divided into about six classes, with getters/setters. I'm guessing that I'm at least calling 360K getters per frame, which I think is a lot of overhead. Each class contains either/and-or 1D or 2D arrays containing custom enumerations, int, Color, or Vector2D, bytes. What if I combined all of the classes into just one, and accessed the contents of each array directly? The code would look a mess, and ditch the concepts of object-oriented coding, but the speed might be much faster. I'm also not concerned about access violations, as any attempts to get/set the data in the arrays will done in blocks. E.g., all writing to arrays will take place before any data is accessed from them. As for casting, I stated that I'm using custom enumerations, int, Color, and Vector2D, bytes. Which data types are fastest to use and access in the .net Framework, XNA, XBox, C#? I think that constant casting might be a cause of slowdown here. Also, instead of using math to figure out which indexes data should be placed in, I've used precomputed lookup tables so I don't have to use constant multiplication, addition, subtraction, division per frame. :)

    Read the article

  • Can getters and setters be inlined when definition and declaration are seperated in .h and .cpp files?

    - by Nathan
    I have searched and have been unable to verify how the GCC compiler will handle inlining getters and setters when declaration is in .h file and definition is in .cpp file. Most seem to say that GCC can't see across these source file barriers and won't be able to inline these at all, while others disagree. I have looked at the documentation and I can't find the answer there either. Did I miss it? I do realize that inlining is a choice made by the compiler and is not always guaranteed, but assuming optimal situations, is it at least possible?

    Read the article

  • Is there a Java unit-test framework that auto-tests getters and setters?

    - by Michael Easter
    There is a well-known debate in Java (and other communities, I'm sure) whether or not trivial getter/setter methods should be tested. Usually, this is with respect to code coverage. Let's agree that this is an open debate, and not try to answer it here. There have been several blog posts on using Java reflection to auto-test such methods. Does any framework (e.g. jUnit) provide such a feature? e.g. An annotation that says "this test T should auto-test all the getters/setters on class C, because I assert that they are standard". It seems to me that it would add value, and if it were configurable, the 'debate' would be left as an option to the user.

    Read the article

  • JSF Pages call ManagedBeans that are not defined on the page and call all getters sometimes more tha

    - by Bill Leeper
    I have several JSF pages that are initializing and accessing ManagedBeans that are not even used on that page. This is creating a really hairy problem for initialization. I either have to make them all session scope and continually make calls to re-inialize or take the performance hit of having them read large amounts of data from the DB whenever they decide to initialize. Some of the managed beans being accessed are not even defined on the page in question. I have done some optimization based on comments related to multiple calls to getters, but I still have the issue that I have a very specialized (and expensive to initialize) bean that is getting called when I don't want it initialized. Any insight into why/what JSF calls might do something like this. I have a very complex page making use of JSTL, Tomahawk and standard JSF tags. I could include code, but its very complex and sensitive in nature.

    Read the article

  • Java: Is clone() really ever used? What about defensive copying in getters/setters?

    - by GreenieMeanie
    Do people practically ever use defensive getters/setters? To me, 99% of the time you intend for the object you set in another object to be a copy of the same object reference, and you intend for changes you make to it to also be made in the object it was set in. If you setDate(Date dt) and modify dt later, who cares? Unless I want some basic immutable data bean that just has primitives and maybe something simple like a Date, I never use it. As far as clone, there are issues as to how deep or shallow the copy is, so it seems kind of "dangerous" to know what is going to come out when you clone an Object. I think I have only used clone() once or twice, and that was to copy the current state of the object because another thread (ie another HTTP request accessing the same object in Session) could be modifying it. Edit - A comment I made below is more the question: But then again, you DID change the Date, so it's kind of your own fault, hence whole discussion of term "defensive". If it is all application code under your own control among a small to medium group of developers, will just documenting your classes suffice as an alternative to making object copies? Or is this not necessary, since you should always assume something ISN'T copied when calling a setter/getter?

    Read the article

  • C++: Copy contructor: Use Getters or access member vars directly?

    - by cbrulak
    Have a simple container class: public Container { public: Container() {} Container(const Container& cont) //option 1 { SetMyString(cont.GetMyString()); } //OR Container(const Container& cont) //option 2 { m_str1 = cont.m_str1; } public string GetMyString() { return m_str1;} public void SetMyString(string str) { m_str1 = str;} private: string m_str1; } So, would you recommend this method or accessing the member variables directly? In the example, all code is inline, but in our real code there is no inline code. Update (29 Sept 09): Some of these answers are well written however they seem to get missing the point of this question: this is simple contrived example to discuss using getters/setters vs variables initializer lists or private validator functions are not really part of this question. I'm wondering if either design will make the code easier to maintain and expand. Some ppl are focusing on the string in this example however it is just an example, imagine it is a different object instead. I'm not concerned about performance. we're not programming on the PDP-11

    Read the article

  • Is this a reasonable way to handle getters/setters in a PHP class?

    - by Mark Biek
    I'm going to try something with the format of this question and I'm very open to suggestions about a better way to handle it. I didn't want to just dump a bunch of code in the question so I've posted the code for the class on refactormycode. base-class-for-easy-class-property-handling My thought was that people can either post code snippets here or make changes on refactormycode and post links back to their refactorings. I'll make upvotes and accept an answer (assuming there's a clear "winner") based on that. At any rate, on to the class itself: I see a lot of debate about getter/setter class methods and is it better to just access simple property variables directly or should every class have explicit get/set methods defined, blah blah blah. I like the idea of having explicit methods in case you have to add more logic later. Then you don't have to modify any code that uses the class. However I hate having a million functions that look like this: public function getFirstName() { return $this->firstName; } public function setFirstName($firstName) { return $this->firstName; } Now I'm sure I'm not the first person to do this (I'm hoping that there's a better way of doing it that someone can suggest to me). Basically, the PropertyHandler class has a __call magic method. Any methods that come through __call that start with "get" or "set" are then routed to functions that set or retrieve values into an associative array. The key into the array is the name of the calling method after get or set. So, if the method coming into __call is "getFirstName", the array key is "FirstName". I liked using __call because it will automatically take care of the case where the subclass already has a "getFirstName" method defined. My impression (and I may be wrong) is that the __get & __set magic methods don't do that. So here's an example of how it would work: class PropTest extends PropertyHandler { public function __construct() { parent::__construct(); } } $props = new PropTest(); $props->setFirstName("Mark"); echo $props->getFirstName(); Notice that PropTest doesn't actually have "setFirstName" or "getFirstName" methods and neither does PropertyHandler. All that's doing is manipulating array values. The other case would be where your subclass is already extending something else. Since you can't have true multiple inheritance in PHP, you can make your subclass have a PropertyHandler instance as a private variable. You have to add one more function but then things behave in exactly the same way. class PropTest2 { private $props; public function __construct() { $this->props = new PropertyHandler(); } public function __call($method, $arguments) { return $this->props->__call($method, $arguments); } } $props2 = new PropTest2(); $props2->setFirstName('Mark'); echo $props2->getFirstName(); Notice how the subclass has a __call method that just passes everything along to the PropertyHandler __call method. Another good argument against handling getters and setters this way is that it makes it really hard to document. In fact, it's basically impossible to use any sort of document generation tool since the explicit methods to be don't documented don't exist. I've pretty much abandoned this approach for now. It was an interesting learning exercise but I think it sacrifices too much clarity.

    Read the article

  • Am I doing getters/setters the right way in Java?

    - by Sergio Tapia
    public class Persona { int Codigo; String Nombre; public Persona(int Codigo, String Nombre){ this.Codigo = Codigo; this.Nombre = Nombre; } public void setCodigo(int Codigo){ this.Codigo = Codigo; } public int getCodigo(){ return this.Codigo; } public void setNombre(String Nombre){ this.Nombre = Nombre; } public String getNombre(){ return this.Nombre; } } Or is there a much shorter (realiable) way to do it?

    Read the article

  • Any way to define getters for lazy variables in Javascript arrays?

    - by LLer
    I'm trying to add elements to an array that are lazy-evaluated. This means that the value for them will not be calculated or known until they are accessed. This is like a previous question I asked but for objects. What I ended up doing for objects was Object.prototype.lazy = function(var_name, value_function) { this.__defineGetter__(var_name, function() { var saved_value = value_function(); this.__defineGetter__(var_name, function() { return saved_value; }); return saved_value; }); } lazy('exampleField', function() { // the code that returns the value I want }); But I haven't figured out a way to do it for real Arrays. Arrays don't have setters like that. You could push a function to an array, but you'd have to call it as a function for it to return the object you really want. What I'm doing right now is I created an object that I treat as an array. Object.prototype.lazy_push = function(value_function) { if(!this.length) this.length = 0; this.lazy(this.length++, value_function); } So what I want to know is, is there a way to do this while still doing it on an array and not a fake array?

    Read the article

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