Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)?
Here is the definition:
public interface IConvertible
{
TypeCode GetTypeCode();
bool ToBoolean(IFormatProvider provider);
byte ToByte(IFormatProvider provider);
char ToChar(IFormatProvider provider);
DateTime ToDateTime(IFormatProvider
provider);
decimal ToDecimal(IFormatProvider
provider);
short ToInt16(IFormatProvider provider);
int ToInt32(IFormatProvider provider);
long ToInt64(IFormatProvider provider);
sbyte ToSByte(IFormatProvider provider);
float ToSingle(IFormatProvider provider);
string ToString(IFormatProvider provider);
object ToType(Type conversionType,
IFormatProvider provider);
ushort ToUInt16(IFormatProvider provider);
uint ToUInt32(IFormatProvider provider);
ulong ToUInt64(IFormatProvider provider);
}
So if I would like to have a class which will implements this
IConvertible interface the I have to implement all of those
methods, right? Or if I don't implement all of them, then I have to
at least make an empty method or throw an Exception, right?.
In my opinion, the better way is to make more interface with fewer methods, for example:
public interface IConvertibleInt
{
short
ToInt16(IFormatProvider provider);
int
ToInt32(IFormatProvider provider);
long
ToInt64(IFormatProvider provider);
}
Or even:
public interface IConvertibleInt16
{
short
ToInt16(IFormatProvider provider);
}
public interface IConvertibleInt32
{
int
ToInt32(IFormatProvider provider);
}
public interface IConvertibleInt64
{
long
ToInt64(IFormatProvider provider);
}
Is my reasoning correct?
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)? Here is...
I need help with the Implementation of an Ordered List (Template Files) public interface OrderedStructure { public abstract int size(); public abstract boolean add( Comparable obj ) throws IllegalArgumentException; public abstract Object get( int pos ) throws IndexOutOfBoundsException; public abstract void remove( int pos ) throws IndexOutOfBoundsException; public abstract void merge( OrderedList other ); } import java.util.NoSuchElementException; public class OrderedList implements OrderedStructure { // Implementation of the doubly linked nodes (nested-class) private static class Node { private Comparable value; private...
Needs Help In Java Programming language Exceptional Cars Purpose To review interfaces and exception usage. Directions Your task is to write a class called Car. Your class should have the following fields and methods: private int position private boolean headlightsOn public Car() - a constructor which initializes position to 0 and headlightsOn to false public Car(int position) - a constructor which initializes position to the passed in value and headlightsOn to false, and it should throw a NegativeNumberException with a...
Part I: Create a doubly linked circular list class named LinkedItemList that implements the following interface: /** * An ordered list of items. */ public interface ItemList<E> { /** * Append an item to the end of the list * * @param item – item to be appended */ public void append(E item); /** * Insert an item at a specified index position * * @param item – item to be...
Array with Iterator. Java style
Implement an array data structure as a class JstyArray<E>
to support the Iterable interface such that the following code
works:
JstyArray<Integer> data;
data = new JstyArray<Integer>(10);
for (int i = 0; i < 10; ++i) {
data.set(i, new Integer(i) );
}
int sum = 0;
for ( int v : data ) {
if (v == null)
continue; // empty cell
sum += v;
}
The iterator provided by this class follows the behaviour of...
Follow program instructions carefully. spacing is important. I think It needs a static void main too. Need to run it! You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following: Data: that hold the x-value and the y-value. They should be ints and must be private. Constructors: A default constructor that will set the values to (2,-7) A parameterized...
I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...
[Continued] Your Course class should have:
1)a getter for the course 'code', so that it is read-only;
2)a getter and setter for the lecturer attribute, so that it is
readable and writable;
3)a constructor that creates the associations shown in the UML
diagram;
4)an enrolStudent method that adds a given Student object into
the 'enrolled' set;
5)a withdrawStudent method that removes a given Student object
from the 'enrolled' set and returns true if the student was
successfully found and removed,...
I need to implement a stack array but the top of the stack has to be Initialize as the index of the last location in the array. //Array implementation of stacks. import java.util.Arrays; public class ArrayStack implements Stack { //Declare a class constant called DEFAULT_STACK_SIZE with the value 10. private static final int DEFAULT_STACK_SIZE = 10; /* Declare two instance variables: 1. An integer called...
This class implements a doubly linked list in which the nodes are of the class DLNode. This class must implement the interface DLListADT.java that specifies the public methods in this class. The header for this class will then be public class DLList implements DLListADT This class will have three private instance variables: • private DLNode front. This is a reference to the first node of the doubly linked list. • private DLNode rear. This is a reference to the last...
Create a linked list with given code Given code: import java.util.Iterator; public interface Set { /** Removes all of the elements from this set */ void clear(); /** Returns true if this set contains no elements @return true if this set contains no elements */ boolean isEmpty(); /** Returns the number of elements in this set (its cardinality) @return the number of elements in this set */ int size(); /** Returns an iterator over the elements in this set @return...