473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

OOP concepts

Hi,
I am trying to implement the following program, using OOP concepts,
but I am a bit confused.

The program is to accept audio files of type mp3(version 1 and 2) and
wma. I need to store the artist of the song. This is implemented in
the audio class as public. In class Audio, I have a method which
checks the type and returns an int according to type.

I implemented two other classes(WMA and MP3) which inherit Audio.
Then implemented another two classes (V1 and V2) and inherit MP3.

The artist is to be identified in the classes V1, V2 and WMA.

A sample code is the following:

Class Audio
{
public string artist;
private string path;

public Audio(string filePath)
{
this.path = filePath;
}

public virtual int checkType()
{
if (wma) // not correct syntax
return 1;
else
return 0;
}

public string getArtist()
{
return artist;
}
} // end class
class MP3 : Audio
{
private Audio myAudio;

public MP3(Audio x)
{
this.Audio = x;
}

public override int checkType()
{
// checking from file what type is and returning data
}

}

class V1 : MP3 // V2 and WMA similar
{
private MP3 myMP3;

public MP3(MP3 x)
{
this.myMP3 = x;
}

public void setArtist()
{
// is to be set here by reading from file
// stored in the artist object found in class Audio
}
}

Now I was trying to acess as following, but not working

Audio audio = new Audio(filePath);
int x = audio.getType(); // assume returned for MP3
MP3 mp3 = new MP3(audio);
int x = MP3.getType(); // assume returned for V1
V1 v1 = new V1(mp3);
v1.setArtist();

Now I was trying to get the artist by
audio.getArist();
but surely it wont work.

Is there another way of how to implement it other than getting the
artist from v1.getArtist();
I hope someone understands my problem
Thanks in Advance
Nov 16 '05 #1
3 1273
Hi!

Xarky wrote:

[...snip...]
The program is to accept audio files of type mp3(version 1 and 2) and
wma. I need to store the artist of the song. This is implemented in
the audio class as public. In class Audio, I have a method which
checks the type and returns an int according to type.

I implemented two other classes(WMA and MP3) which inherit Audio.
Then implemented another two classes (V1 and V2) and inherit MP3.

The artist is to be identified in the classes V1, V2 and WMA.
So you added an "artist" property to the Audio class. That's o.k.

A sample code is the following:

Class Audio
{
public string artist;
private string path;

public Audio(string filePath)
{
this.path = filePath;
}

public virtual int checkType()
{
if (wma) // not correct syntax
return 1;
else
return 0;
}

public string getArtist()
{
return artist;
}
} // end class
class MP3 : Audio
{
private Audio myAudio;
Why do you need this Audio attribute in here ?
If you'd really need a constructor with a Audio as an Argument, you can take
the argument's filePath and store it in MP3's filePath...

public MP3(Audio x)
{
this.Audio = x;
}
like this:

public MP3(Audio x)
{
this.path = x path;
}

But you can also override the Audio constructor:

public MP3(string filePath) : base(filePath)
{
}


public override int checkType()
{
// checking from file what type is and returning data
}
Why would you want to check it here ? Let V1 return a value and V2 another
one...

}

class V1 : MP3 // V2 and WMA similar
{
private MP3 myMP3;
Same as for MP3 class applies here: Why do you need a type MP3 attribute ?
public MP3(MP3 x)
This is incorrect. Must be

public V1(MP3 x)

But you will not need it...
{
this.myMP3 = x;
}
Just create a constructor like

public V1(string filePath) : base(filePath)
{
this.setArtist();
}

public void setArtist()
{
// is to be set here by reading from file
// stored in the artist object found in class Audio
}
}

Now I was trying to acess as following, but not working

Audio audio = new Audio(filePath);
int x = audio.getType(); // assume returned for MP3
Why do you create an Audio instance ? As far as I can see, you do not need
it at all...
MP3 mp3 = new MP3(audio);
int x = MP3.getType(); // assume returned for V1
Why do you create an MP3 instance ? As fas as I can see, you do not need it
at all...
V1 v1 = new V1(mp3);
v1.setArtist();
Just do

V1 myMusic = new V1(filePath);

Your new instance will use filePath as it's audio file and initialize the
artist based upon that file...

[...snip...]
Is there another way of how to implement it other than getting the
artist from v1.getArtist();
What's wrong in getting the Artist from your V1 instance ?
I hope someone understands my problem


I hope I did; if I didn't, just say so ;-)

Nov 16 '05 #2

The problem is that Audio class determines what type of music is.

If I do
V1 x = new V1(filePath);
filePath, may result to a WMA or a V2.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
xarky wrote:
The problem is that Audio class determines what type of music is.
The superclass is not supposed to know anything of its subclasses, so you'd
have a problem here.

If I do
V1 x = new V1(filePath);
filePath, may result to a WMA or a V2.


You'll have to know what kind of object to create prior to the creation. You
might consider creating a factory class being responsible for determining
the instance to create:

class AudioFactory
{
public AudioFactory()
{
}

public Audio createAudio(string filePath)
{
// check the file, extract information about Artist and Type
// create an instance of the appropriate Audio subclass
// return the proper class
}
}

You might think of creating some kind of AudioInterface as well.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RK | last post by:
I was reading the Concepts manual and was puzzled by this sentence. Can anyone elaborate on this: <snip> Tables are the basic unit of data storage in an Oracle database. Database tables hold all...
1
by: ravinder | last post by:
I wanted to develop a multithreaded program using OO concepts on windows platform. Problem: I have to simulate two layers(similar to TCP/IP stack layers), and the layer functionality is of finite...
6
by: enki | last post by:
I had read that you should use classes to represent concepts. How does this work and what kind of concepts should be reresented as classes.
3
by: Kappa | last post by:
Hello, Can anyone suggest me a good intermediate level C# book that teaches OOP concepts too. I saw Beginning C# Objects: From Concepts to Code by Jacquie Barker, it seems good but I want a...
3
by: Robert | last post by:
I've been working with ASP.NET for about a year and I think I'm on the verge of "getting it." I suspect that if I came to understand a few key concepts it would all come together. One of those "key...
3
by: User1013 | last post by:
I have the Javascript definitive guide book but I'm hoping someone can tell me what "language concepts" are being employed by the following code, so that I can look up the right parts in the book:...
20
by: W Karas | last post by:
Would the fear factor for concepts be slightly reduced if, instead of: concept C<typename T> { typename T::S; int T::mem(); int nonmem(); };
30
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”....
1
by: aswinikg | last post by:
HI I am a newbie to 'C' and embedded application . I have a code in which the input parameter is being assigned in two ways (i) Runtime through user (ii)...
1
by: Swathika | last post by:
Hi, Sometimes, you never get chance to learn 'Advanced Design Concepts and Real-time Scenarios' from institutes or through book-learning. But, in my blog, I have gathered some of the amazing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.