|
-
Oct 12th, 2005, 05:59 AM
#1
Thread Starter
Hyperactive Member
Classes
Hello,
I need to create object to hold a collection of information about movies. Storing it, I think to use serialization.
I'm new in .NET so I have very little expierence how to do this best. Please suggest the best solution.
Movie object will contain lost of information like title, year, description, director, actors list and other. I would need quickly load/update information. Also I would need to find movie with some conditions.
Waiting your suggestion how to create such objects and how to save it (binary, xml or other methods?).
Regards in advance,
Good luck
-
Oct 12th, 2005, 06:23 AM
#2
Re: Classes
A class is basically a description of an object, code that takes the 'shape' of the object being modelled.
So you'd set up something like:
PHP Code:
public class Movie
{
private string _title = null;
private int _year = -1; //any default will do
//then a constructor:
public Movie(string title, int year)
{
_title = title; //store the initialising data
_year = year;
}
//add methods to let you access the data:
public int Year
{
get { return _year; }
set { _year = value; }
}
public string Title
{
get { return _title; }
get { _title = value.trim(); }
}
}
Then once you are ready to sort and search your movies you can implement IComparable.
MSDN will help you with implementing interfaces. 
Hope that helps a bit.
Last edited by wossname; Oct 12th, 2005 at 06:27 AM.
I don't live here any more.
-
Oct 12th, 2005, 06:25 AM
#3
Re: Classes
It'd probably be best for you to save your movies list as XML (using XML serialization) because it makes it pretty to look at in a browser for example.
Binary serialization is best used where speed and efficiency is required, as it is a lot faster and smaller than XML but is less flexible.
I don't live here any more.
-
Oct 12th, 2005, 06:26 AM
#4
Addicted Member
Re: Classes
Well, your best bet is to create objects for each of the data structures you want to encapsulate.
If you are using a database, then a data layer would be in order, which you can get free from Microsoft. If not, then you need methods on your objects to load/save from your data store.
Each class should have private fields representing things like title, year made etc and public properties to expose those fields to the outside world.
Use a collection class to store your movies in memory, and probably best to inherit from System.Collections.CollectionBase to do this.
So you would have ...
Movies (Collection Class)
--- Private Collection of Movie
Movie
--- Name
--- Year Made
etc etc.
I know this is all very broad and rough, but should be enough to get you started! 
GL
Look into the heart of infinity and find your truth
Colonel Tom Edwards: This is the most fantastic story I've ever heard
Jeff Trent: And every word of it's true, too
Colonel Tom Edwards: That's the fantastic part of it
ROFL 
-
Oct 12th, 2005, 06:52 AM
#5
Addicted Member
Re: Classes
Aha, Woss beat me to it!
Look into the heart of infinity and find your truth
Colonel Tom Edwards: This is the most fantastic story I've ever heard
Jeff Trent: And every word of it's true, too
Colonel Tom Edwards: That's the fantastic part of it
ROFL 
-
Oct 12th, 2005, 07:16 AM
#6
Thread Starter
Hyperactive Member
Re: Classes
So if movie has list like actors I shoud create another two classes like Actors which is collection of actor class?
I'm thinking to use binary serialization (it faster) and add additional funtion to export/import to/from xml later.
When creating such project, shoud I create abstract classes, interfaises, event handlers? Example: I'm planning to store file information in movie object, files collection. File can be movie, subtitle, image etc. Every of them would have base properties like filename, path, size and additional like, language, resoliution, bitrate. So I can create three different classes or inherit from base.
Where I can found good acticles/examples of creating such things in the best way. I can create it on my own, but probably it would be dirty and not hightly optimized.
-
Oct 12th, 2005, 07:55 AM
#7
Re: Classes
Quite honestly I would advise you to get a book from the library about C# programming. All the good books on this topic will discuss interfaces, classes, events and so forth in detail. They will also be a decent primer to OO (object orientated)programming in general.
Avoid "Sams: Teach yourself C# in 21 days" books because they are invariably awful.
I don't live here any more.
-
Oct 12th, 2005, 08:24 AM
#8
Thread Starter
Hyperactive Member
Re: Classes
Thanks wossname, I'll do this definitely.
Answer to another question and I'll have good start point how to do this.
After I would create Movie class and Movies collection I want to add custom function to Movies object. Like this:
VB Code:
public Movie Search(CriterionList criterions)
{
//loop criterions with some logic
}
Question is how to create collection of criterions? This class shoud be not strongly typed, but also should accept only know criterions?
Damm, I have read about it in some book, but can't remember. Maybe you know how?
 Originally Posted by wossname
Quite honestly I would advise you to get a book from the library about C# programming. All the good books on this topic will discuss interfaces, classes, events and so forth in detail. They will also be a decent primer to OO (object orientated)programming in general.
Avoid "Sams: Teach yourself C# in 21 days" books because they are invariably awful.
-
Oct 14th, 2005, 03:06 AM
#9
Thread Starter
Hyperactive Member
Re: Classes
Ok, in technical terms I want to:
Crete enum list of awaible properties using reflection.
Example:
If I have two classes:
File { constructor, methods, properties.. }
Movie { File [] Files, other properties, constructor, methods)
I want to have enum list of all Movie and File properties (I need File properties, becouse File is declered in Movie class - in other words I need to do this using recursion)
Last edited by Norkis; Oct 14th, 2005 at 03:14 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|