New answers tagged

1

Checking the file suffix seems easy, but ultimately pointless. A file named foo.bar might be a valid jpeg file. A file named reallyIsA.jpg might be a nasty virus. Remember when some corporate firewalls forbid you from emailing .exe or .zip files and everybody just changed the extensions? IMO, your API should specify "a file in one of these image formats: ...


1

You should provide an API with documentation. In your documentation you should document what unusal inputs are handled well, what incorrect inputs you will detect and how you will respond to them - and what incorrect inputs you will not detect. And your implementation should follow that documentation. Your API can be written with the attitude "calling it ...


0

In this example and in most other real world examples the overhead of validation will be negligible compared to the work your API is supposed to do. For starters you may want to create a class MediaFile that encapsulates the input of your API. All validation can then be done in the constructor of the media file class. MediaFile could be abstract and you ...


0

Would this be an acceptable solution if the number of data members or fields of the class is large? export class State { private _dirty: boolean = false; private _data1: string = ''; private _data2: number = 0; constructor( d1: string, d2: number ) { this._data1 = d1; this._data2 = d2; } get dirty() { ...


1

Based on comments, here's a dirty-bit implementation that should work: class Dirtyable { private _isDirty:Boolean = false; get isDirty():Boolean { return _isDirty; } private _example:String; get example():String { return _example; } set example(val):String { if (val !== _example) _isDirty = true; ...



Top 50 recent answers are included