w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

Initialize an dynamically allocated object by already existing object
You are assigning the pointer. You need to assign the content: *pObject2 = Object1; pObject2 is a pointer. If you assign it you are making it to point to Object1, forgetting the pointer to the dynamically created instance in the process. Instead you need to assign the instance, *pObject2. That will invoke ClassName<T>::operator=, which is either autogenerated to assign all members, or hopefully manually written to do whatever else is the right thing for the type. Edit: Of course, as Guido Kanschat realized in the other question, while this is what was wrong with your attempt, you should really use the copy constructor directly. Why initialize the second object with arbitrary junk when you are going to reinitialize it with object1 anyway.

Categories : C++

How to initialize objects of array which has been created dynamically?
This is really, really bad design. I assume, that your method Battle could be an instance method of a class Game, which you didn't provide to us. Then I strongly recommend, that the Battle method should NOT create instances of objects it works with. It should only take them and do a battle action (compute lives, etc.). So, create these objects elsewhere and then just post them to the method. class Game { List<Bishop> bishops = new List<Bishop>() { new Bishop(..), ... }; List<Knight> knights = new List<Knight>() { new Knight(..), ... }; void Battle(List<Unit> first, List<Unit> second) { foreach(var f in first) { // get random unit from the second collection and attack him f.Attack(GetRandomKnigh

Categories : C#

Object Oriented Design for generic hibernate object
UserDefinedField on Marin Fowler's web site may be a perfect starting point for exploring general answers to this question. As for Hibernate: It's really designed for statically binding tables to objects and you may have significant problems if you change the schema while running. You can implement the following solutions, though: Serialized LOB (you serialize your Map into a binary field or - using JSON/XML - a text field). This is a half-and-half approach - half tabular/normal form/SQL and half not-SQL. So, if this approach is attractive, you might want to consider going all-in with a NoSQL database as discussed later Attribute table, where your customized attributes are stored in a key-value pair table that joins to to the master table. This can be mapped in Hibernate using Indexed C

Categories : Java

Object-oriented design: Giving too much responsibility to a value object
There are an infinite number of ways to design this system (that's what makes developing software so fun) some ways are better than others. The provided answer is not the best but it works. You have to have some way of an Employee to escalate a call by doing somekind of callback to the Callhandler. Whether that is done by passing around the Callhandler or having Employees and callhandlers listening to events are both good ideas. The given solution is simpler and therefore more easy to understand for the target audience. An event based solution is more complicated, harder to write but more scalable and easier to modify. For example, if you had to add a new feature for some kind of "overseer" to monitor how often Employees successfully resolve calls versus how many times they escalat

Categories : Java

Object oriented programming in c# object definition
It looks like you are trying to learn more about C# and classes. Let me give you a few things that may help you out. This is not a direct answer to your question, as more info is needed to properly answer it. But a few pointers in general may help you out and let you clarify the issue: In your class, the property _car is not initialized with an instance of a BMW, so it will be null when new instances are created. You then have the line public _car machine = new _car() This line is most likely inside of a class, as you can't have it just in a C# file on it's own. If this came from a Console.App, it's probably inside the Main Program so it run when you start it, and then it would be available to the rest of the app at runtime. In another_class, you have a method which check to see i

Categories : C#

PHP Cart with Object Oriented PHP
I got it, first I did when I click a link step by GET and the ID Code I need after seto it in a cookie, each cookie with an ID. Then I check if cookie has registered with the IDs. Not the best and most correct, but it works (more or less). Now another problem, I need to click two times to get the result as it passes by id and need to be caught refresh = / I think it was a bit confusing but it is the maximum that dyslexia allows me to do hehehe Here I set up the structure with the data I have in my product page: <a href="single-produtos.php?id_p=<?php echo $id_get;?>&cod=<?php echo $res->codigo; ?>">add</a> <?php $cod_get = $_GET['cod']; setcookie("SITENAME_cod_".$id_get."", $cod_get, time()+3600, "/","", 0); ?> And here I have a loop checki

Categories : PHP

Object Oriented Issue in c#
As I see, you just want to write user command handler. There are no big problem. Just make a dictionary (var GraphsType -> Graph). var dictionary = new Dictionary<GraphsType, Graph>() { { GraphsType.None, GraphObject }, { GraphsType.UndirectedGraph, UndirectedGraphObject }, { GraphsType.DirectedGraph, DirectedGraphObject }, }; And use it: dictionary[GraphType].AddVertex(v); If your Graph, UndirectedGraph, DirectedGraph are static classes, you must save in dictionary it's type (typeof(Graph)) and then on type use reflection to find method and invoke it (dictionary[GraphType].GetMethod(..).Invoke(...))

Categories : C#

How to use an S4 method in an object-oriented way
Typically classes and methods are defined in a package. Packages have a (locked) name space in which the symbols are defined. The user can redefine any symbol, but do this in the global environment; the underlying symbol is still accessible. In base R: > pi [1] 3.141593 > pi = "apple" > pi [1] "apple" > base::pi [1] 3.141593 Or a little more subtly, showing that R knows about functions versus variables > log(1:5) [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 > log = "pine" > log [1] "pine" > log(1:5) [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 The underlying understanding of what is going on involves environments (of which a name space is a special case), the search() path, and R's association of symbol with value in an environment. Symbols m

Categories : R

Object Oriented Programming in PHP
As you already know -> lets you access an attribute or a method. Obviously the attribute or method could contain another object as well. The second -> will access an attribute or method of the inner object. As an example: class A { public $b = null; public function __construct() { $this->b = new B(); } public function returnCinB() { return $this->b->c; } } class B { public $c = null; public function __construct() { $this->c = new C(); } } class C { } $a = new A(); var_dump($a->returnCinB()); // class C#3 (0) { // }

Categories : PHP

Object-Oriented Programming in Python
Here is what I think you want: class Buildings(object): def __init__(self, function): self.function = function # Don't name an attribute the same as a method def myMethod(self): # Use self.function instead of function if self.function == '1': print 'blablabla' elif self.function == '2': print 'blablabla' Granary = Buildings('1') Granary.myMethod() Edit: Going by what you said in your comments, I have to say the answer depends on what you plan to do. Every scenario is different and in one, something might not be the best solution even though it was the best in another. Usually, there isn't really a reason to make a whole class with only one method. For example, in your above code, you can also do: def Buildings(f

Categories : Python

Object-oriented models and backbone.js
A simple approach to this (possibly to simple for your implementation) would be to override the model's parse method to return suitable attributes: var modelFoo = Backbone.Model.extend({ parse: function ( json ) { var i18n = ... ; if (i18n.prefLang && _.isArray(json.label)) { // json.label = "complex structure" } return json; } }); That way only your model worries about how the data from the server is formatted without adding another layer of abstraction.

Categories : Backbone Js

Trying to model with object-oriented javascript
You could have your stats values be methods instead of member variables. That way, you could compute during the call a given stat, for exemple knight.defense(). In turn, the method defense() in your character class could call defense() from the faction class, defense() from the equipmentSet class, etc. The advantage of this is you could add additional stat modifiers whenever, for example if you decide you want a perk system or something. Each faction class could then override their defense() function for their modifier. I wouldn't call this the most object-oriented way but that's how I'd do it myself as a Javascript programmer. Addendum: Pluto's answer is also how you get "classes" (instead of individual objects) that are reusable. As mentioned I'd also make Faction a class instead of j

Categories : Javascript

Object oriented design issue in C++
You seem to be confusing a couple of issues. First of all, you say you want to delete a class from within itself. That is normally not a good idea. The key here is that there is a difference between allocating and deallocating memory, and having a valid object. You could have a bool overheated variable in your class that you will set to true when the Car overheats. Then your loop can look like this: class Engine { private: bool overheated; public: bool isOverheated() const { return overheated; } void rev(); // Rest of implementation ... }; void Engine::rev() { temperature += 2; if (temperature > 50) overheated = true; } class Car { /* ... */ }; int main() { Car car; while (!car.engine.isOverheated()) { car.engine.rev(); } } Using NULL

Categories : C++

object oriented programming in android
Your SendSMS class is an Activity. You should never instantiate an Activity yourself, because none of the life cycle methods will be called then. Let the system start your Activities (using intents). If you just need a normal class that you instantiate don't inherit Activity. To get access to methods only found in Activity or Context pass in a valid Context in your class constructor. Assuming your onClick method is defined in an Activity: public void onClick(View arg0) { String p = "+989357835774"; String m = "test"; SendSMS sms = new SendSMS(this); sms.sms(p, m); } public class SendSMS { private Context context; public SendSMS(Context context) { this.context = context; } public void sms (String phonno , String Message){ PendingInte

Categories : Java

Having some problems with Object Oriented Java, is this right?
Is it right to pass in the GameState contructor an instance of the GameStateManager just to acess his methods for state changing? No. You should only ever have one instance and one reference of the manager. That means you should use an instance-based system. For example: GameStateManager instance = GameStateManager.getInstance(); That way you can access it statically. This can be done in such a manner: // in GameStateManager.java private static GameStateManager instance; protected static GameStateManager getInstance(){ if(instance == null){ instance = new GameStateManager(); //private constructor } return instance; } I assume protected will work here, on the basis that all GameState instances are in the same package as the GameStateManager.

Categories : Java

Difference between message-oriented and RPC oriented web services
In RPC based the methods in a Web service are called through a RPC, i.e. in a synchronous way through a specific port and protocol. But message-oriented is Message based Web Services the methods are called through an HTTP request using SOAP. Read this excellent article.

Categories : Java

how can i initialize my array when i cant initialize as null?
In Java everything is a pointer behind the scenes. So when you do mynums[]=null, you are pointing to a null. So what is null[i]? That is where your NPE comes from. Alternatively when you point it to an array, then you are actually accessing the i'th element of the array.

Categories : Java

How do I dynamically add an object to my Flex 3 Array Collection?
addItem() method should work anyway. Please, make sure that you: initialize collection before filling it out: HardwareItems = new ArrayCollection(); initialize objects before filling it out: newItem = {}; Anyway, remember, that ArrayCollection has a property 'source', which is actually an array. So, instead of addItem you may use the push() method as following: var HardwareItems:ArrayCollection = new ArrayCollection(); var newItem:Object = {}; newItem['merch'] = lblMerchID.text; newItem['item'] = qnn(gat).label; newItem['qual' = ""; newItem['loc'] = ""; newItem['id'] = qnn(gat).id; HardwareItems.source.push(newItem); HardwareItems.refresh();

Categories : Actionscript

hide attibutes in object oriented perl
Take a look at the code. It loads a C library (dll on Windows) with DynaLoader. The rest is only constructors. The properties (like SmptHost) are not kept in the Perl datastructure. It is just passed on to C function calls. I'm not even sure you can have several distinct objects at the same time. That's why there is nothing in the blessed hash. You cannot just hide the data. There are no private methods in normal Perl objects. There is always a way to get to the stuff. There are object frameworks that make it harder to serialize it with Data::Dumper, but that is not the purpose of these. Take a look at Class::Std::Fast::Storable for example.

Categories : Perl

Safe and secure Object Oriented insertion with PDO
Probably not. You have introduced injection in the field names. If you can guarantee the field names are always generated by your code and never from an outside source, that might be OK. But this is a public method. So any bit of code in the system might try to do something "smart" and end up opening up a hole by passing a parameter to your insert method. You should escape your incoming field names by putting them in quotes (or if you are using MySQL and haven't enabled ANSI compatibility, use backtics). You also must escape any quotes within the name. $fields = implode(',', array_map(function($name) { return '"' . str_replace('"', '""', $name) . '"' ; }, array_keys($values))); For the values, you should just use positional paramters (?) or make up your own names. I don't thi

Categories : PHP

Correct Concept for Object-Oriented Programming
Yes. The subclass gets all the superclasses methods. If you override one then that method no longer has the superclasses implementation of it. So in this case, you will get the objectMethod of the superclass and the methodOne of the subclass when you instantiate a subclass instance and call either method.

Categories : IOS

Object Oriented Program Design Questions
First, you need to aware about OPEN CLOSE PRINCIPLE. This is for oo design approach. and try to use interface which limits the scope of any class with defined methods. To access any object's value, always go for a POJO class. Here are the links which you needed how to design efficiently.1.Open Close Principle2. Interface Segregation Principle3.other design principles

Categories : Java

Efficiently use mysqli in object oriented setting
So how do I do this properly and efficiently? This really has nothing to do with using MySQLi in a procedural versus OOP way. What this has to do with is the following line: $con = connectDB(); This will recreate the database connection on every query. Which, as you noted, is not efficient. There are many ways to solve this. For example: Use the mysqli class directly. Pass $con to executeQuery() (Dependency Injection) Create a DB class with both connectDB() and executeQuery(). I usually use mysqli directly as I see no reason to wrap the native class. I create the connection object globally (in a config file) and use Dependency Injection when other objects/functions need it.

Categories : PHP

Histogram of Oriented Gradients object detection
Yes, HOG (Histogram of Oriented Gradients) can be used to detect any kind of objects, as to a computer, an image is a bunch of pixels and you may extract features regardless of their contents. Another question, though, is its effectiveness in doing so. HOG, SIFT, and other such feature extractors are methods used to extract relevant information from an image to describe it in a more meaningful way. When you want to detect an object or person in an image with thousands (and maybe millions) of pixels, it is inefficient to simply feed a vector with millions of numbers to a machine learning algorithm as It will take a large amount of time to complete There will be a lot of noisy information (background, blur, lightning and rotation changes) which we do not wish to regard as important The

Categories : Opencv

How do object oriented concept works in Perl
Now what is the use of the pre-declaration of the hash (not empty hash)? and why is the @_ supplied in the last part of the list? what for? When you assign a list to a hash, the list is treated as a list of key-value pairs. If a key appears twice, the latter value will overwrite the earlier one. As such, the key-values before the @_ are defaults which can be overridden by the arguments passed to new (@_). Which again, I have no idea what it does. It creates a new object, passing the values of the invocant to the constructor in order to duplicate the invocant.

Categories : Perl

Reasoning behind Object Oriented Access Specifiers
I have a general question regarding the reason for object oriented access specifiers. I have never completely understood the reasoning why they exist and just thought they were there as a very rudimentary form of code-security but after looking at the discussion on this thread Amongst other reasons, they allow for control of access to class fields/properties, and they allow for binding of properties that will allow listeners to be notified of any changes to them. I have understood that I am completely wrong and they don't help with security at all. This seems to me to be an overly broad and vague statement. They allow control of access to a property, and so that in and of itself increases "security". If you disagree, then to further help you with this, consider telling us your f

Categories : Java

PHP object-oriented access to a method and issues with $this
If you use :: it refers to a static function. If you created an object, you have to do it like: $obj = new PageModel( ); $obj->find(" YOUR QUERY "); public function find( $q ){ } If you have a static method (in these functions $this does not reffer to the object, because you did not create a new object. PageModel::find( $q ){} public static function find ( $q ){ }

Categories : PHP

Interaction of objects in object-oriented programming
I don't know python, but in C# it would look something like this: public class House(){ public double X { get; set; } public double Y { get; set; } public double Area(){ return X*Y; } public double Value { get; set; } } Not sure how you define a dictionary in python, but basically in C# like pseudocode, you want Dictionary<double, List<House>> HousesWithValue = new Dictionary<int, List<House>>(); My original understanding of the process was that you would have a whole collection of houses with known values that get added to the dictionary. You have a new house that has no value. So when you add it to the city, first, check the dictionary based on the area, and from that list, you can get the average price from the house values. B

Categories : Python

Object Oriented Design/How to set up class structure
You don't necessarily need to nest your classes. Just create one class, as MadProgrammer was suggesting, that is an event, implement that to your Calendar class and use it as needed. If you wanted to delete a calendar, you might include some method that makes sure to delete all events from inside that calendar. But just deleting the calendar object should do the trick.

Categories : Java

Relational databases and object oriented environment
I agree with the comments to your question; you should really avoid re-inventing the wheel here and go with an ORM, if at all possible. Speaking from experience, you're going to end up writing code and solving problems that have long ago been solved and it will probably take you more time in the long run. However, I understand that sometimes there are constraints that don't permit the use of an ORM. Here are some articles that I have found helpful: This first article is an old one but it explains the different options that you have for data access design patterns. It has a few different patterns and only you can really decide which one will be best for you but it sounds like you might want to look at the Repository Pattern: http://msdn.microsoft.com/en-us/magazine/dd569757.aspx This

Categories : C#

Python object oriented design concepts
Your next step could be to use a class generated with the collections.namedtuple() factory: from collections import namedtuple Company = namedtuple('Company', 'quantity price') companies = {'AMP': Company(1000, 2.50), 'ANZ': Company(2000, 17.00), 'BHP': Company(500, 54.30)} companies['AMP'].quantity Note that like tuple objects, namedtuple-derived objects are immutable. You cannot assign to the attributes, you'd create a new object instead. You'd only need to switch to custom classes if you needed to add functionality to your objects; add methods that act on the data associated with an object: class Company(object): def __init__(self, quantity, price): self.quantity = quantity self.price = price def profit(self, newprice): return self.quantity * (ne

Categories : Python

how to create Object key & value in JavaScript dynamically from array string
I would go like this : var value=[["xyz","01","abc"],["def","02","ghi"]]; // notice it's an array of array instead of an array of objects var elements = []; for (var i = 0; i< value.length; i++) { var elem = new Object(); for (var j=0; j< key.length; j++) { elem[key[j]] = value[i][j]; } elements.push(elem); }

Categories : Javascript

MongoDB - Dynamically update an object in nested array
There's no direct way to do that, because MongoDB doesn't support an update-expression that references the document. Moreover, the $ operator only applies to the first match, so you'd have to perform this as long as there are still fields where AnArray.Time is of $type string. You can, however, perform that update client side, in your favorite language or in the mongo console using JavaScript: db.collection.find({}).forEach(function (doc) { for(var i in doc.AnArray) { doc.AnArray[i].Time = new Date(doc.AnArray[i].Time); } db.outcollection.save(doc); }) Note that this will store the migrated data in a different collection. You can also update the collection in-place by replacing outcollection with collection.

Categories : Json

knockout dynamically replace a object in an observable array
An observableArray is really an observable with extra additional array-like features, not a plain javascript array. So to get to your array you need to resolve the observable first : viewModel.people()[0].name = "new value"; edit If you want that a change in the .name property of one of the object in the array triggers a modification to the page, the property will need to be observable too. Something like this: var viewModel={ people : ko.observableArray([ { name: ko.observable('Bert') }, { name: ko.observable('Charles') }, { name: ko.observable('Denise') } ])}; // Update: viewModel.people()[0].name("new value");

Categories : Knockout Js

whats wrong with my code - object oriented javascript
You need to use, because your getter method is nor returning any value to the caller. In your getter, you are calling getData method which return the value of data but that value is not sent back the the caller of getter this.getter = getData or this.getter = function () {return getData();}

Categories : Javascript

Unable to increment variable (object oriented programming)
Why do you need an increment() method and why do you increment by 3 every time? The number variable is static so you have access to it anywhere inside your class. Use it and increment it in the Constructor. public EnemyShip() { System.out.print("- Initial position: "); position = Global.keyboard.nextInt(); System.out.print("- Initial velocity: "); velocity = Global.keyboard.nextInt(); life = 10; boolean justHit = false; number++; System.out.println("Enemy #" + number); } Every time you call new EnemyShip(); you will see the statement Enemy #[some number] If you want to remember which EnemyShip has which number, you can add an instance field. private int shipNumber; public EnemyShip() { System.out.print("- Initial position: "); position

Categories : Java

Returning object oriented json from sparql queries
The JSON output for SPARQL is documented in SPARQL 1.1 Query Results JSON Format, and specifically section 3.2.2 Encoding RDF Terms describes how the RDF is encoded in the JSON. Note that the JSON output is really just for encoding the results of a SPARQL query, not for creating JSON objects that correspond to a particular object model. Your best bet is probably to take the results you're getting and manipulate them yourself. There are still a few things that might be helpful from the SPARQL side, though. group_concat for combining values That said, maybe the following can help you get something that will work a bit better for you. If you have data like this: @prefix : <http://example.org/> . :object :hasA1 :b1, :b2, :b3, :b4 ; :hasA2 :b5 . and a query like this:

Categories : Json

How to define a derived property in object oriented Matlab
You can use the property access methods: http://www.mathworks.co.uk/help/matlab/matlab_oop/property-access-methods.html To define get/set functions - the get function should allow you to return values computed from other members. The section "When to Use Set Methods with Dependent Properties" in the link above gives an example for this.

Categories : Matlab

Object Oriented PHP Email Contact Form Not Sending
I might be wrong, but I think it's to do with your $contents variable. You've only set it within the sendMail class, but you used $this->contents. Try setting private $contents; as an instance variable, or just use $contents on this line: $sendmail = mail($this->toEmail, $this->subject, $this->message, $this->contents, $headers); (should be:) $sendmail = mail($this->toEmail, $this->subject, $this->message, $contents, $headers);

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.