Search Results

Search found 456 results on 19 pages for 'getter'.

Page 8/19 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Getters and Setters are bad OO design?

    - by Dan
    Getters and Setters are bad Briefly reading over the above article I find that getters and setters are bad OO design and should be avoided as they go against Encapsulation and Data Hiding. As this is the case how can it be avoided when creating objects and how can one model objects to take this into account. In cases where a getter or setter is required what other alternatives can be used? Thanks.

    Read the article

  • CodeDOM: Adding DebuggerStepThroughAttribute to property

    - by Dont Ask
    I know how to add a DebuggerStepThroughAttribute to a method or a constructor, usually you add it to the CustomAttributes collection of a code member. But I don't see a way to do this for the setter and getter of a C# property, because neither of them provides this collection where you add the attributes. Does anyone have a clue?

    Read the article

  • Complex HashMap has different hashCode after serialization

    - by woezelmann
    I am parsing a xml file into a complex HashMap looking like this: Map<String, Map<String, EcmObject> EcmObject: public class EcmObject implements Comparable, Serializable { private final EcmObjectType type; private final String name; private final List<EcmField> fields; private final boolean pages; // getter, equals, hashCode } EcmObjectType: public enum EcmObjectType implements Serializable { FOLDER, REGISTER, DOCUMENT } EcmField public class EcmField implements Comparable, Serializable { private final EcmFieldDataType dataType; private final EcmFieldControlType controlType; private final String name; private final String dbname; private final String internalname; private final Integer length; // getter, equals, hashCode } EcmFieldDataType public enum EcmFieldDataType implements Serializable { TEXT, DATE, NUMBER, GROUP, DEC; } and EcmFieldControlType public enum EcmFieldControlType implements Serializable{ DEFAULT, CHECKBOX, LIST, DBLIST, TEXTAREA, HIERARCHY, TREE, GRID, RADIO, PAGECONTROL, STATIC; } I have overwritten all hashCode and equal methods by usind commons lang's EqualsBuilder and HashCodeBuilder. Now when I copy a A HashMap this way: Map<String, Map<String, EcmObject>> m = EcmUtil.convertXmlObjectDefsToEcmEntries(new File("e:\\objdef.xml")); Map<String, Map<String, EcmObject>> m2; System.out.println(m.hashCode()); ByteArrayOutputStream baos = new ByteArrayOutputStream(8 * 4096); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(m); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); m2 = (Map<String, Map<String, EcmObject>>) ois.readObject(); System.out.println(m.hashCode()); System.out.println(m2.hashCode()); m.hashCode() is not equal to m2.hashCode() here is my output: -1639352210 -2071553208 1679930154 Another strange thing is, that eg. 10 times m has the same hashcode and suddenly on the 11th time the hashcode is different... Any ideas what this is about?

    Read the article

  • Flex DownloadProgressBar preloader override

    - by Shawn Simon
    I'm watching this video, which is pretty good http://www.gotoandlearn.com/play?id=108 It shows how to inherit from DownloadProgressBar to create a customer preloader for your flex app. The DownloadProgressBar class has an overridable getter for the property 'preloader.' Isn't this poor design? What does a property called preloader have anything to do with a class for a DownloadProgressBar?

    Read the article

  • Use a subclass object to modify a protected propety within its superclass object

    - by gadmeer
    Sorry for the crappy title I failed to think of a better version for my Java question. I am right now using Java version: 1.6.0_18 and Netbeans version: 6.8 Now for the question. What I've done is created a class with only one protected int property and next I made a public method to Set the int property to a given value. Then I made an object of that class and used said public method to set the int property to 5. Now I need your help to create another class that will take said object and expose it's protected int property. The way I could think of doing this was to create a sub class to inherit said class and then create a method to Get the int property of the super class. I kind of succeeded to create the code to Get the int property but now I can't figure out how to use this new sub class to reference the object of the super class. Here are the 2 classes I have thus far: public class A { protected int iNumber; public void setNumber ( int aNumber ) { iNumber = aNumber; } } public class B extends A { public int getNumber() { return super.iNumber; } } I created an object of 'A' and used its method to set its property to 5, like this: A objA = new A(); objA.setNumber ( 5 ); Now I want to create an object of 'B' to output the int stored within the property of 'objA'. I've tried to run this code: B objB = (B) objA; String aNumber_String = String.valueOf( objB.getNumber() ); System.out.println( aNumber_String ); but I got the error: "java.lang.ClassCastException" on the first line B objB = (B) objA; Please is there anyway of doing what I am trying to do? P.S. I am hoping to make this idea work because I do not want to edit class A (unless I have no choice) by giving it a getter method. P.P.S Also I know it's a 'bad' idea to expose the property instead of making it private and use public setter / getter methods but I like it this way :). Edit: Added code tags

    Read the article

  • How to provide an own contentView for using -drawRect?

    - by mystify
    I want to use -drawRect: in an UITableViewCell subclass but it is covered by contentView. So the best option seems to be that I make a UIView subclass with my -drawRect: code and use that as contentView. But how could I feed my UITableViewCell subclass with that contentView? UITableViewCell creates that on its own when the contentView property is accessed. Would I simply override the getter method and then provide my own view there?

    Read the article

  • error logging in zend

    - by pradeep
    i am using zend for 1st time..i am facing problems in finding errors. when a setter and getter function name mismatch i get a an error...but the error is show sometimes and not all the time...how do i log such errors.is there any separate log for this?

    Read the article

  • yii documentation

    - by nucleartux
    where find topic with description of setters and getters of form fields? example: field: <?php echo $form->textField($model,'tagsArray',array('size'=>60,'maxlength'=>255)); ?> getter: function getTagsArray()

    Read the article

  • Method Vs Property

    - by obsoleteattribute
    Hi, I'm a newbie to .NET. I have a class called Project, a project can have multiple forecasts.Now If I want to check if the projects has any forecasts or not should I use a readonly boolean property called HasForecast() or should I use a method named HasForecast() which basically returns a boolean value.From framework design guidelines I came to know that methods should be used when the operation is complex,since here I'm retrieving the value of forecasts from DB should I consider method, or since it is a logical data member should I use a property.If I use a property can I call a method in DBLayer from its getter.Please explain Regards, Ravi

    Read the article

  • Why Directly Accesing property is not recommended in OOPs PHP?

    - by Parth
    If I have a class "person" with a property $name and its getter(get_name()) and setter(set_name()) methods, then after instantiating the objects and setting the property i.e. $paddy = new person(); $paddy->set_name("Padyster Dave"); echo "Paddy's full name: ".$paddy->name; //WHY THIS IS NOT RECOMMENDED... In the above code $paddy->name;WHY THIS IS NOT RECOMMENDED?

    Read the article

  • creating dynamic rich:dropdownmenu

    - by santhana sankar
    MethodExpression methodExpression = application.getExpressionFactory().createMethodExpression( FacesContext.getCurrentInstance().getELContext(), "#{PrismBacking.onItemClick}", null, new Class[] { ActionEvent.class }); menuItem.setActionExpression(methodExpression); I created a dynamic drop down as above my creating action listener but the listener was not called. I included the method inside the getter of dropdown in backing bean. Do I have to configure the action listener in any of the config files. kindly help.

    Read the article

  • Concurrent Linked HashMap java

    - by Nilesh
    Please help me use/create Concurrent LinkedHashMap. As per my belief, if I use Collections.synchronizedMap(), I would have to use synchronized blocks for getter/setter. If I use ConcurrentSkipListMap, is there any way to implement a Comparator to store sequentially. I would like to use java's built in instead of third party packages. Thanks

    Read the article

  • Synthesized property of a protocol not seeing superclass' ivar

    - by hyn
    I have a situation where my subclass is not seeing the superclass' instance variable x. The ivar is obviously @protected by default, so why do I get a compiler error "x undeclared"? - (CGSize)hitSize { // Compiler error return size; } EDIT: hitSize is a property of a protocol my subclass is conforming to. The problem was that I had hitSize @synthesized, which was the culprit. The question then is why can't the synthesized getter see the ivar?

    Read the article

  • Change TrayIcon Tooltip from ProgressMonitorDialog

    - by Raven
    Hello, i am using the Eclipse RCP trayitem, which is described in Vogellas tutorials here: http://www.vogella.de/articles/RichClientPlatform/article.html#systemtray The requirement now is not only to show the name of the app in the tooltip but also a percentage while doing lengthy operations. I understand that the trayitem attribute is a private from ApplicationWorkbenchWindowAdvisor, so I added a getter and setter method. The only thing missing is a possibility to access the trayitem instance from my ProgressMonitorDialog instance. Can you tell me, how you would solve this puzzle? Thanks

    Read the article

  • Practical examples of using symbols in Scala?

    - by Jesper
    Scala has symbols - names that start with a single quote ' and which are a kind of string constants. I know symbols from Ruby (where they start with a colon). In Ruby they are used for some meta-programming tasks, like generating getters and setters for member variables (for example attr_reader :name to generate a getter for name). I haven't seen a lot of use of symbols in Scala code yet. What are practical uses for symbols in Scala?

    Read the article

  • Can JAXB generate a generic class?

    - by dinesh
    Can I get JAXB 2.0 XJC compiler to generate a generic class for me? Something as simple as:- public class Shape<T> { T myShape; // getter / setter } I see references for this in the spec but am not sure I'm reading it right. I always get Object references.

    Read the article

  • WPF Binding to IDictionary<int,MyType>.Values Doesn't Respond to Property Changes?

    - by Phil Sandler
    I am binding a ListView a property that essentially wraps the Values collection (ICollection) on a generic dictionary. When the values in the dictionary change, I call OnNotifyPropertyChanged(property). I don't see the updates on the screen, with no binding errors. When I change the property getter to return the Linq extension dictionary.Values.ToList(), without changing the signature of the property (ICollection) it works with no problem. Any reason why the Values collection bind and notify properly without projecting to an IList<?

    Read the article

  • Code generator tool to generate a property and backing field

    - by MattSlay
    I'm working in VS2008 and C#, and I'm looking for a (free) code generator tool to generate a property with getter and setter, as well as the backing private field to go with. The template thingy in VS does not make the field to go with it. Just looking for something a little bit better. I once saw a web site where you could build this code, then cust-and-paste it from the web page to your code.

    Read the article

  • NoSuchMethodErrors say the darndest things

    - by keynan21
    So, I'm working in eclipse were everything compiles and runs correctly. However, when compiling under ant for the build server, A large number of tests fail with a NoSuchMethodError saying: class A implements B interface B extends C C requires method getSyncID() // standard getter for an int field. A.java contains getSyncID() A.class contains getSyncID() and yet the Error is still thrown. Does anyone know how the hell this could happen? how to fix it.

    Read the article

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